Skip to main content
Inspiring
November 15, 2022
해결됨

Field validation for Military Date Time Group and GeoCoordinates (LAT/LONG)

  • November 15, 2022
  • 1 답변
  • 5814 조회

I have been tinkering with regex for the past week attempting to find validation scripts for both the Military Date Time Group (DTG) expressed as DDHHMM(Z) MMMYYYY -- with the (Z) being primary for Zulu time but modifiable if necessary and for fixed geocoords (LAT/LONG).

 

Thus far, I have only found lat/long regex but have been unable to get them working -- still attempting with the following example -- and I am still looking for DTG.

lat/long example: 

 


If anyone has previously skinned this cat, my sincerest thanks in advance for an assist. 

 

PS Apparently, adobe does not like the regex example I attempted to post. :S 

이 주제는 답변이 닫혔습니다.
최고의 답변: try67

The Reg Exp you posted was invalid. I tried to fix it, but not sure it worked...

You can use this code as the custom Validation script of either longitude and latitude fields:

 

var reg = new RegExp("(^\-?\d+(\.\d+)?),\s*(\-?\d+(\.\d+)?)$");
if (event.value && reg.test(event.value)==false) {
	app.alert("Invalid value.");
	event.rc = false;
}

1 답변

ls_rbls
Community Expert
Community Expert
November 16, 2022

When you refer to using regular expression, what exactly are you trying to do?

 

DTG is very complicated to do with JavaScript if your PDF will be distributed accross different countries (regions and timezones) because of the timezone-dependent offset value. 

 

See here: https://special-ops.org/military-time-military-date-time-group-explained/

 

 

Whatever the user enters in that field, the core JavaScript interpreter will grab a timezone from whichever Network Time Protocol (NTP)  server is setup on each user's computers (date/time settings) and will append the offset value as part of that timestamp.

 

But if this is a PDF that will be used to disseminate a task to subordinates (i.e. issuing orders), and the DTG field would be timezone-independent, then is fairly easy to customize with a script, for example.

 

If you have a script try sharing it again please or do a screenshot of what you have on screen.

 

And would you also mind clarifying what do you mean by latitude and longitudes; that is a whole separate thing from DTG unless you're referring about the timezone offset values that you want to append to the desired DTG date.

Inspiring
November 16, 2022

Thank you for your time and your response.  I'm actually looking at two separate validated fields -- one for lat long and one for the DTG.  It was asked if I could somehow account for the local alpha character timezone designator to which I said I'd look into it -- leading to my initial help request.  I also told them I would prefer to stick with Zulu time only as the lat/long ship's position would clearly indicate the time zone -- potentially just a little more work for those accepting the report forms.

As these forms will primarily be used offline while underway, Zulu appears the easiest way -- and written orders are never issued in local (L) time, always and only in Zulu.  I merely wish to validate the proper format is being entered by the user (ie. DDHHMMZ mmm yyyy & lat/long) to reduce fat-fingers -- of which I suffer daily. 😉

 

Here is the script I've been attempting to get working for the lat/long

<script type="text/javascript">

var latitude = document.getElementById(lat).value;
var longitude = document.getElementById(lng).value;

var reg = new RegExp^(\-?\d+(\.\d+)?),\s*(\-?\d+(\.\d+)?)$;

if( reg.exec(latitude) ) {
//do nothing
} else {
//error
}

if( reg.exec(longitude) ) {
//do nothing
} else {
//error
}

</script>

Inspiring
November 17, 2022

The Reg Exp you posted was invalid. I tried to fix it, but not sure it worked...

You can use this code as the custom Validation script of either longitude and latitude fields:

 

var reg = new RegExp("(^\-?\d+(\.\d+)?),\s*(\-?\d+(\.\d+)?)$");
if (event.value && reg.test(event.value)==false) {
	app.alert("Invalid value.");
	event.rc = false;
}

I had also been attempting to get the following working as well with little to no success.  As you understand this stuff inside and out, you may have a better idea what this means. 

function checkIfValidlatitudeAndlongitude(str) {
const regexExp = /^((\-?|\+?)?\d+(\.\d+)?),\s*((\-?|\+?)?\d+(\.\d+)?)$/gi;
return regexExp.test(str);
}
checkIfValidlatitudeAndlongitude("9.9824245,76.5703886"); // true
checkIfValidlatitudeAndlongitude("9.2323,1212notValid"); // false