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 16, 2022

So you may be in luck.

 

I have done this before in one of my PDFs without the need to validate with a regular expression.

 

To make it easier on myself,  I employed a regular date field with the built-in calendar picker but I used a custom format for the date of "yyyymmdd".

 

And as the user selects the desired date on that date field, the same date  will be displayed in DTG format on  another  textfield that I placed adjacent to the date field.

 

I've also learned in this process that this alleviates the fact that, you will always run into users that (for some unknown reason to me) can't stop messing around with sensitive documents) , it eliminates the headache on how to teach them what not to do with the required workflow. 

 

I will post back with an example of the util.printd() methid that I used instead of using regular expressions for this particular formatting.

 

You can evaluate if this works for you.