Skip to main content
Inspiring
November 15, 2022
Answered

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

  • November 15, 2022
  • 1 reply
  • 5831 views

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 

This topic has been closed for replies.
Correct answer 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 reply

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>

ls_rbls
Community Expert
Community Expert
November 25, 2022

The script looks and works great.  Is there a way to prevent the user from entering an incorrect format/data?  FYSA, My end-state is to minimize the inevitable fatfingering for data collection on SITREPS and Noon reports.  Nautical lat/longs (ex 38° 53' 50.9254"N/S; 77° 2' 15.2339E/W) are the most notorious screwups during data entry and make accurately tracking vessels difficult to impossible.

 

Thank you again for the effort and hard work.  It is truly impressive.

 

Yes,

 

Is there a way to prevent the user from entering an incorrect format/data? 

 

I am still working on it.

 

The script that I posted needs improvements and it is not a final work.