• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Simplified DTG Validation Script

Contributor ,
Nov 28, 2022 Nov 28, 2022

Copy link to clipboard

Copied

Aaaannndd... I'm back, yet again.  I've been at this months and still feel no better or more intelligent regarding scripting in Acrobat.  At this rate it will be decades before I'm even somewhat proficient -- or possibly longer. 

 

I'm still attempting to write a validation script for just a Military Time field that will error out with any incorrect input. 

This is what I've worked out thus far and now trying to figure out how to have the field reject any input that doesn't follow these guidelines -- to include anyone attempting to use a colon seperator or numbers outside a 23 hour 59 minute clock:

$('#startTimeInput').jqxDateTimeInput({
formatString : "HHMM" + timeCodeLetter .toUpperCase()
});

 

As my posts should make it clear, I have absolutely no idea what I'm doing.  When I get something to work without the expertise here, in the Navy we call this "FM" or "f*ckin' magic". while estatic, it certainly doesn't feel like I've learned anything.  Thankfully, there's no FM involved with the SME's here.  My thanks in advance for any and all assistance.

 

I've been working virtually the same script for a full DTG and plan on applying everything learned in this thread to the following script as well:

 

$('#startTimeInput').jqxDateTimeInput({
formatString : "ddHHMM" + timeCodeLetter + "mmm yyyy"  .toUpperCase()
});

FYSA:  For anyone stumbling upon this, as I've seen it discussed in many different threads, there is no 2400 or 0000 used in Military Time -- it's always a "lost" minute where all official log entries are either 2359 or 0001.

TOPICS
JavaScript , PDF forms

Views

17.7K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 5 Correct answers

Community Expert , Nov 29, 2022 Nov 29, 2022

Hi,

 

I am not sure if this will help or not, but if I was looking to limit a field to a specific range of numbers, I would use a RegEx to achieve this, placing this in a custom script on the validation would mean that a user could not enter any value that does not pass the validation check.

 

The code I would use is

// I am not a regex expert and I am sure someone could simplify this down, but this is the basic of it
// ([0]{3}[1-9]) - makes sure 0000 is not allowed 
// ([0][12][0-5][0-9]) - if
...

Votes

Translate

Translate
Community Expert , Nov 29, 2022 Nov 29, 2022

Hi,

You can write a validation script:

event.rc=event.value=="" || (/^((((0|1)\d)|([2][0-3]))([0-5]\d))?$/.test(event.value) && event.value!="0000");

or a custom keystroke script to manage the typing:

if (!event.willCommit) {
	var aTester=event.value.split("");
	aTester.splice(event.selStart, event.selEnd-event.selStart, event.change);
	var testeChaine=aTester.join("");
	var RegExTime=/^((((0|1)\d?)|([2][0-3]?))([0-5]\d?)?)?$/;
	event.rc=RegExTime.test(testeChaine) && testeChaine!="24" && testeC
...

Votes

Translate

Translate
Community Expert , Nov 29, 2022 Nov 29, 2022

Hi,
You are right because you certainly used the first version of the script I gave you. Then I changed a bit it without indicate that. Since, I did it...

Try the attached file and you will not able to validate the "322469Z JUL 1031" entry.

The custom keystroke script is a bit more "sensitive" to write... I will let you know.

@+

Votes

Translate

Translate
Community Expert , Dec 09, 2022 Dec 09, 2022

Hi,

You reported a malfunction for my script:

quote
.. any time the DTG (full format ddHHMM(z) mmm yyyy) has a day (dd) entry of "10", "20", or "30", the script will not allow a time entry to exceed two (2) zeroes. So only the HH can contain 00 and then it will not allow a third zero as would be required within the first nine (9) minutes after midnight to 0009 (technically 0001 through 0009 as we've previously discussed there is no 0000 or 2400 used).

And effectively, it's a case I didn't think abo

...

Votes

Translate

Translate
Community Expert , Dec 12, 2022 Dec 12, 2022

...and as required, here it is for only the time:

// Custom keystroke script
if (!event.willCommit) {
	var aTester=event.value.split("");
	aTester.splice(event.selStart, event.selEnd-event.selStart, event.change);
	var testeChaine=aTester.join("");
	var RegExTime=/^((((0|1)\d?)|([2][0-3]?))([0-5]\d?)?)?$/;
	event.rc=RegExTime.test(testeChaine) && testeChaine!="24" && Number(testeChaine.substr(2,1))<=5 && testeChaine!="0000";
} else {
	var RegExTime=/^(((0|1)\d)|([2][0-3]))([0-5]\d)$/;
	event.rc=
...

Votes

Translate

Translate
Community Expert ,
Nov 29, 2022 Nov 29, 2022

Copy link to clipboard

Copied

Hi,

 

I am not sure if this will help or not, but if I was looking to limit a field to a specific range of numbers, I would use a RegEx to achieve this, placing this in a custom script on the validation would mean that a user could not enter any value that does not pass the validation check.

 

The code I would use is

// I am not a regex expert and I am sure someone could simplify this down, but this is the basic of it
// ([0]{3}[1-9]) - makes sure 0000 is not allowed 
// ([0][12][0-5][0-9]) - if it does start with a 0 then it can only be a 1 or a 2 after it, followed by 0-5 and then by 0-9
//([1][0-9][0-5][0-9]) - if it starts with a 1, then it can be followed by 0-9, then 0-5, then 0-9 again.
// ([2][0-3][0-5][0-9]) - if it starts with a 2, it can only be followed by a 0,1,2,3 and then 0-5 and 0-9
var myRegExp = new RegExp("([0]{3}[1-9])|([0][12][0-5][0-9])|([1][0-9][0-5][0-9])|([2][0-3][0-5][0-9])");
event.rc = myRegExp.test ( event.value);

 I hope this helps

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 29, 2022 Nov 29, 2022

Copy link to clipboard

Copied

THANK YOU!!  YOU ARE A ROCKSTAR! 🙂  It's working quite well and I will now attempt to use it as a baseline for adding the full DTG (ddHHMM(z) mmm yyyy).  I truly appreciate the assist.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 29, 2022 Nov 29, 2022

Copy link to clipboard

Copied

Hi,

You can write a validation script:

event.rc=event.value=="" || (/^((((0|1)\d)|([2][0-3]))([0-5]\d))?$/.test(event.value) && event.value!="0000");

or a custom keystroke script to manage the typing:

if (!event.willCommit) {
	var aTester=event.value.split("");
	aTester.splice(event.selStart, event.selEnd-event.selStart, event.change);
	var testeChaine=aTester.join("");
	var RegExTime=/^((((0|1)\d?)|([2][0-3]?))([0-5]\d?)?)?$/;
	event.rc=RegExTime.test(testeChaine) && testeChaine!="24" && testeChaine!="0000";
} else {
	var RegExTime=/^((((0|1)\d)|([2][0-3]))([0-5]\d))?$/;
	event.rc=event.value=="" || (RegExTime.test(event.value) && event.value!="0000");
}

...but for my information, what is the time indicated for midnight?

@+

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 29, 2022 Nov 29, 2022

Copy link to clipboard

Copied

Interestingly enough, there is no written time indicated for midnight.  It took a few years of getting yelled at as a young Sailor for using 0000 or 2400 when making log entries.  Quartermaster's (QMs) are typically those in charge of verifying accuracy and validating log books prior to the Ship's Navigator sending them to the Naval Archives and they are INSANE about invalid/incorrect log entry's.  I've been yelled at my so many QM's over the years we do not have enough fingers and toes between us to count. 😉  The 2400/0000 is typically considered "the lost or missing minute" as it is never supposed to be used.  I'm unsure of the history of 2400/0000 omission but I know someone who would likely have the answer and will get back to you if you'd like.  An individual making the log entry will decide on either 2359 or 0001 -- I've noticed human nature typically leads to 2359 being used and I guess it's so the entry doesn't appear "late". LOL!.  

Anyway, probably more than anyone would ever care to know about the military's use of the 24 hour clock. 🙂

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 29, 2022 Nov 29, 2022

Copy link to clipboard

Copied

...could you give me a few examples for "the full DTG (ddHHMM(z) mmm yyyy)"?

@+

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 29, 2022 Nov 29, 2022

Copy link to clipboard

Copied

A full Miltary DTG consists of the Day, Time, Time Zone, Month, and Year in the following format:

ddHHMM (Time Zone) mmm yyyy and would  look like the following example (for the moment I'm typind this):

291124Q NOV 2022 or

291624Z NOV 2022

 

In a DTG, the day of the month is limited to 0-31, the time is limited to 0001-2359, the time zone is limited to A-I and K-Z (J was excluded to prevent confusion with I and as some alphabets do not have one), the month is always limited to the first three (3) characters spelling the name (i.e. JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, & DEC) and always capitalized, and the year in a full DTG is always four (4) digits but can be truncated to two (2) digits for informal message traffic, memos, letters, forms, and some data collection. The two (2) digit format is less common since the Y2K issues are still in the memory of the senior Brass but as the newbies fleet up, they will forget and I'm certain it will show up more frequently outside msg traffic and log entries as time progresses. 

 

I used the Quebec "Q" time zone as it's local EST but it would be "R" Romeo during the summer months of EDT.  The vast majority of message traffic and log entries will utilize Zulu "Z" -- second example -- with the use of a local time zone dependent on a number of unimportant factors.. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 29, 2022 Nov 29, 2022

Copy link to clipboard

Copied

Try this validate new script:

 

var RegExFullMiltaryDTG=/^(((0[1-9])|((1|2)\d)|(3[01]))(((0|1)\d)|(2[0-3]))([0-5]\d)[A-Z][ ]((JAN)|(FEB)|(MAR)|(APR)|(MAY)|(JUN)|(JUL)|(AUG)|(SEP)|(OCT)|(NOV)|(DEC))( 20)\d{2})?$/;
if (RegExFullMiltaryDTG.test(event.value)) {
	var theDay=Number(event.value.substr(0,2));
	var theMonth=event.value.substr(8,3);
	var theYear=Number(event.value.substr(12));
	var bissextile=theYear%4==0 && (theYear%100!=0 || theYear%400==0)?1:0;
	var dayOK=1;
	if ((theMonth=="APR" || theMonth=="JUN" || theMonth=="SEP" || theMonth=="NOV") && theDay>30) var dayOK=0;
	else if (theMonth=="FEB" && !bissextile && theDay>28) var dayOK=0;
}
event.rc=dayOK;

 

I will try soon to give you a custom keystroke script!

@+

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 29, 2022 Nov 29, 2022

Copy link to clipboard

Copied

Just entered it into the custom validation script but it doesn't limit the entries to the thresholds of a DTG.  I can put in 322469Z JUL 1031 without issue... while this is obviously an extreme, the ability to prevent fatfingering (which I am probably more guilty than most) is paramount to ensure those receiving the reports do not have to make repeated data-calls... of which I have received more than more than my fair share to account for my aforementioned fatfingering. ;).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 29, 2022 Nov 29, 2022

Copy link to clipboard

Copied

Hi,
You are right because you certainly used the first version of the script I gave you. Then I changed a bit it without indicate that. Since, I did it...

Try the attached file and you will not able to validate the "322469Z JUL 1031" entry.

The custom keystroke script is a bit more "sensitive" to write... I will let you know.

@+

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 30, 2022 Nov 30, 2022

Copy link to clipboard

Copied

You got me! Your attached works like a champ! Thank you very much and I would bet a shot of good bourbon that once the handful of forms your script is going into are released into the wild, your script will propagate throughout DoD and USG in short order. Fantastic work and my sincerest thanks! 🙂  Quick question, is it possible to add ([A-I,K-Z]) to the regex to account for timezones?  Or would you recommend an entirely seperate field -- maybe a pulldown menu?  I'm trying to keep things as simple as possible for anyone coming along after me who may have to modify any of the forms -- of course they'd probably have a better grasp on this stuff than I've managed to accumulate. 😉

 

Anxiously standing by for the keystroke and again, my sincerest thanks. 🙂

 

[Content edited by moderator]

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 30, 2022 Nov 30, 2022

Copy link to clipboard

Copied

++EDITED REPLY,

 

Well,

 

I guess I made it late to the party.

 

No need for separate fields with this tool, although is a lot easier to mek up a PDF for DTG with separate fields.

 

Below is the script that I've been working on.

 

You may create a textfield and name it "goodtest", then copy and paste the script in the Actions sections and select Mouse Up event.

 

Give it a try.

 

I got the Regex for the coordinates validating correctly but I am not fully done and the Year box and Timezone need some work around with the current Regex that I was trying to figure out.

 

Is a little choppy still, but overall I think is a good approach and fatfingering-fool proof; it needs a few tweaks here and there.

 

 

//// MILITARY DATE TIME GROUP MODAL DIALOGUE BOX /////
//// DECLARE A FUNCTION INSIDE OF A VARIABLE

     var military =

     {
    
        DateTimeGroup: function()

        {
          return app.execDialog(military);
        },

        theLATITUDE:"LATITUDE:",  

        theLONGITUDE:"LONGITUDE:",

        theDAY:"DAY:",

        theHOURS:"HOUR:",

        theMINUTES:"MINUTES:",

        theTIMEZONE:"TIMEZONE:",

        theMONTH:"MONTH:",

        theYEAR:"YEAR:",

       
        // INITIALIZE THE DIALOGUE FUNCTION

        initialize: function(dialog)

        {
          this.result = "Cancel";

          dialog.load(

            {
              "lats": this.theLATITUDE,

              "long": this.theLONGITUDE,

              "days": this.theDAY,

              "hour": this.theHOURS,

              "mins": this.theMINUTES,

              "zone": this.theTIMEZONE,

              "mont": this.theMONTH,

              "year": this.theYEAR,

           }

          );

        },



       // VALIDATE ALL USER INPUT

        validate: function(dialog)

        {

          // VALIDATE BLANK FIELDS AND ALERT USER IF EMPTY

          
           var blankFields = dialog.store();

           var verifyBlankFields = ( blankFields["lats"].length != 0 &&
                                     blankFields["long"].length != 0 &&
                                     blankFields["days"].length != 0 &&
                                     blankFields["hour"].length != 0 &&
                                     blankFields["mins"].length != 0 &&
                                     blankFields["zone"].length != 0 &&
                                     blankFields["mont"].length != 0 &&
                                     blankFields["year"].length != 0 );
                                          
          if (!verifyBlankFields) app.alert("Complete all of the required Blanks");

          return verifyBlankFields;

         },
       

        // IF FIELDS ARE COMPLETE CONCATENATE STRINGS AND POPULATE TARGET FIELD "goodtest"

        commit: function(dialog)

        {
           var militaryDTG  = dialog.store();


               this.theLATITUDE = militaryDTG["lats"];

               this.theLONGITUDE = militaryDTG["long"];

               this.theDAY = militaryDTG["days"];

               this.theHOURS = militaryDTG["hour"];

               this.theMINUTES = militaryDTG["mins"];

               this.theTIMEZONE = militaryDTG["zone"];

               this.theMONTH = militaryDTG["mont"];

               this.theYEAR = militaryDTG["year"];


            getField("goodtest").value = ( militaryDTG["days"]+
                                           militaryDTG["hour"]+
                                           militaryDTG["mins"]+ "(" +
                                           militaryDTG["zone"].toUpperCase()+ ")"+" "+
                                           militaryDTG["mont"].toUpperCase()+ " " +
                                           militaryDTG["year"]+ " " +
                                           militaryDTG["lats"]+", "+
                                           militaryDTG["long"] );




     // VALIDATE LATITUDE AND ALERT USER IF ERROR

          
           var latitude = /[-+]90.[0]{7}$|[012345678]{1}\d{1}.[0]{7}$|[012345678]{1}\d{1}.\d{7}$/;

             if(latitude.test(militaryDTG["lats"]) == false) 

             {
              app.alert("C E N T I M E T E R - L E V E L   P R E C I S E   P O I N T   P O S I T I O N I N G\n\n\n----------  I  M  P  O  R  T  A  N  T\n\tD  E  T  A  I  L  S              --------------------------------------------------\r\r\n\t•   LATITUDES IN DECIMAL DEGREES MUST HAVE A PREFIX\r\r\n\t•   LATITUDES CANNOT BE GREATER THAN 90 DEGREES\r\r\t•   USE THE PLUS '' + '' SIGN FOR DEGRESS NORTH\r\r\t•   OR USE THE MINUS '' - '' SIGN FOR DEGREES SOUTH\r\r\t•   USE 2 DIGITS TO THE LEFT OF THE DECIMAL POINT\r\r\t•   AND 7 DIGITS TO THE RIGHT OF THE DECIMAL POINT\r\r\r\n\t     E X A M P L E  :      [ '' +90.0000000 '' ]    O R    [ '' -89.9999999 '' ]\r\rThe Dialogue Window will restart now", 3);

        event.rc = militaryDTG["lats"]="";  
 
     }

    
    // VALIDATE LONGITUDE AND ALERT USER IF ERROR

    var longitude  = /[-+]180.[0]{7}$|[1]{1}[01234567]{1}[\d]{1}.[\d]{7}$|[-+]\d{2}.\d{7}$/;

     if(longitude.test(militaryDTG["long"]) == false) 

     {

      app.alert("C E N T I M E T E R - L E V E L   P R E C I S E   P O I N T   P O S I T I O N I N G\n\n\n----------  I  M  P  O  R  T  A  N  T\n\tD  E  T  A  I  L  S              --------------------------------------------------\r\r\n\t•   LONGITUDES IN DECIMAL DEGREES MUST HAVE A PREFIX\r\r\n\t•   LONGITUDES CANNOT BE GREATER THAN 180 DEGREES\r\r\t•   USE THE PLUS '' + '' SIGN FOR DEGRESS EAST\r\r\t•   OR USE THE MINUS '' - '' SIGN FOR DEGREES WEST\r\r\t•   USE 2 TO 3 DIGITS TO THE LEFT OF THE DECIMAL POINT\r\r\t•   AND 7 DIGITS TO THE RIGHT OF THE DECIMAL POINT\r\r\r\n\t     E X A M P L E  :      [ '' +180.0000000 '' ]    O R    [ '' -179.9999999 '' ]\r\rThe Dialogue Window will restart now", 3);

         event.rc = militaryDTG["long"]="";  
 
    }


  // VALIDATE DAY AND ALERT USER IF ERROR

   var day = /31|30|[2]{1}$/;

    if(day.test(militaryDTG["days"]) == false) {

        app.alert("USE 2 DIGITS ONLY  [ 01 TO 31 ] TO INDICATE THE DAY", 3);

        event.rc = militaryDTG["days"]="";  

     } 



   // VALIDATE HOURS AND ALERT USER IF ERROR

    var hours = /01|0[0-3]{1}|2[0-3]{1}$/;

    if(hours.test(militaryDTG["hour"]) == false) {

        app.alert("USE 2 DIGITS ONLY  [ 01 through 23 ] TO EXPRESS HOURS IN MILITARY TIME", 3);

         event.rc = militaryDTG["hour"]="";  
 
 
     } 




   // VALIDATE MINUTES AND ALERT USER IF ERROR

     var minutes = /^([0-5]{1}\d)*$/;

     if(minutes.test(militaryDTG["mins"]) == false) {

         app.alert("USE 2 DIGITS ONLY  [ 00 through 59 ] TO EXPRESS MINUTES IN MILITARY TIME", 3);

         event.rc = militaryDTG["mins"]=""; 
 
 
     } 



   // VALIDATE MILITARY TIMEZONE AND ALERT USER IF ERRORS


 
var timeZone = /[(A)]|[(B)]|[(C)]|[(D)]|[(E)]|[(F)]|[(G)]|[(H)]|[(I)]|[(K)]|[(L)]|[(M)]|[(N)]|[(O)]|[(P)]|[(Q)]|[(R)]|[(S)]|[(T)]|[(U)]|[(V)]|[(W)]|[(X)]|[(Y)]|[(Z)]/;  

    if(timeZone.test(militaryDTG["zone"]) == false) {

        app.alert("USE ONE WORD CHARACTER LETTER IN UPPER CASE ONLY  [ A TO Z ] TO EXPRESS MILITARY TIME ZONE", 3);

         event.rc = militaryDTG["zone"]="";  
 
     } 

      
    // VALIDATE MONTH AND ALERT USER IF ERROR

    
    var month = /(JAN)|(FEB)|(MAR)|(APR)|(MAY)|(JUN)|(JUL)|(AUG)|(SEP)|(OCT)|(NOV)|(DEC)/;

     if(month.test(militaryDTG["mont"]) == false) {

       app.alert("USE 3 LETTERS ONLY IN UPPER CASE TO INDICATE THE MONTH [ A TO Z ]\r\rFOR EXAMPLE: USE ''NOV'' INSTEAD OF ''nov''", 3);

        event.rc = militaryDTG["mont"]="";  
 

       } 


   // VALIDATE YEAR AND ALERT USER IF ERROR

   var year = /^[\d]{2}\[\d]{2}?/;

    if(year.test(militaryDTG["year"]) == false) {

        app.alert("USE 4 DIGITS ONLY FOR THE YEAR", 3);

        event.rc = militaryDTG["year"]=""; 
  
     } 
               
  },  // CLOSE COMMIT DIALOGUE FUNCTION



////////// CREATE DIALOGUE BOX TITTLE ///////////////

  description:

  {
     name: "[  M I L I T A R Y  D A T E  T I M E  G R O U P  ( D T G )  ]  ---  C E N T I M E T E R - L E V E L  P R E C I S E  P O I N T  P O S I T I O N I N G  T O O L ",

     elements:

      [
        {
          type: "view",
          elements:
          [
            {
               align_children: "align_top",
               type: "cluster",
               elements:
              [
                {
                  type: "view",
                  elements:
                  [
                    {
                      alignment: "align_fill",
                      font: "default",
                      item_id: "lats",
                      name: "LATITUDE:",
                      type: "static_text",
                        },
                        {
                          height: 23,
                          item_id: "lats",
                          type: "edit_text",
                          width: 150,
                        },
                      ]
                    },
                    {
                      type: "view",
                      elements:
                      [
                        {
                          item_id: "long",
                          name: "LONGITUDE:",
                          type: "static_text",
                        },
                        {
                          height: 23,
                          item_id: "long",
                          type: "edit_text",
                          width: 150,
                        },
                      ]
                    },


                    {
                      type: "view",
                      elements:
                      [
                        {
                          item_id: "days",
                          name: "DAY:",
                          type: "static_text",
                        },
                        {
                          height: 23,
                          item_id: "days",
                          type: "edit_text",
                          width: 50,
                        },
                      ]
                    },

                    {
                      type: "view",
                      elements:
                      [
                        {
                          item_id: "hour",
                          name: "HOUR:",
                          type: "static_text",
                        },

                        {
                          height: 23,
                          item_id: "hour",
                          type: "edit_text",
                          width: 50,
                        },
                      ]
                    },


                    {
                      type: "view",
                      elements:
                      [
                        {
                          item_id: "mins",
                          name: "MINUTES:",
                          type: "static_text",
                        },

                        {
                          height: 23,
                          item_id: "mins",
                          type: "edit_text",
                          width: 50,
                        },
                      ]
                    },


                    {
                      type: "view",
                      elements:
                      [
                        {
                          item_id: "zone",
                          name: "TIMEZONE:",
                          type: "static_text",
                        },

                        {
                          height: 23,
                          item_id: "zone",
                          type: "edit_text",
                          width: 60,
                        },
                      ]
                    },



                    {
                      type: "view",
                      elements:
                      [
                        {
                          item_id: "mont",
                          name: "MONTH:",
                          type: "static_text",
                        
                        },

                        {
                          height: 23,
                          item_id: "mont",
                          type: "edit_text",
                          width: 50,
                        },
                      ]
                    },



                    {
                      type: "view",
                      elements:
                      [
                        {
                          item_id: "year",
                          name: "YEAR:",
                          type: "static_text",
                        },

                        {
                          height: 23,
                          item_id: "year",
                          type: "edit_text",
                          width: 60,
                        },
                      ]
                    },     
                  ]
                },


   // Set the OK and CANCEL button objects

   { 
    alignment: "align_right",

    type: "ok_cancel",

    ok_name: "Submit",

    cancel_name: "Cancel"

            },
          ]
        },
      ]
    }
  };



(event.target.value == "") ? ([military.DateTimeGroup() == "Submit", {}]): this.resetForm(["goodtest"]); 



 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 30, 2022 Nov 30, 2022

Copy link to clipboard

Copied

Hi,

Where must be added ([A-IK-Z]) in the regex? Instead of ([A-Z]) or somewhere esle???

Here is my proposal for managing the typing.

A function in document-level script:

function dayChecking(theValue) {
	var theDay=Number(theValue.substr(0,2));
	var theMonth=theValue.substr(8,3);
	var theYear=Number(theValue.substr(12));
	var bissextile=theYear%4==0 && (theYear%100!=0 || theYear%400==0)?1:0;
	if ((theMonth=="FEB" && theDay>29) || ((theMonth=="APR" || theMonth=="JUN" || theMonth=="SEP" || theMonth=="NOV") && theDay>30)) dayOK=0;
	else if (theValue.length>15 && theMonth=="FEB" && !bissextile && theDay>28) dayOK=0;
}

...and the custom keystroke script:

if (!event.willCommit) {
	event.change=event.change.toUpperCase();
	if ((event.value.length==6 && event.selStart==6) || (event.selStart==6 && event.selEnd>7)) event.change+=" ";
	else if ((event.value.length==10 && event.selStart==10) || (event.selStart==10 && event.selEnd>11)) event.change+=" 20";
	var aTester=event.value.split("");
	aTester.splice(event.selStart, event.selEnd-event.selStart, event.change);
	var testeChaine=aTester.join("");
	var RegExFullMiltaryDTG=/^(((0[1-9]?)|((1|2)\d?)|(3[01]?))((((0|1)\d?)|(2[0-3]?))([0-5]\d?)?([A-Z]([ ]((((J(AN?)?)|(F(EB?)?)|(M(AR?)?)|(A(PR?)?)|(M(AY?)?)|(J(UN?)?)|(J(UL?)?)|(A(UG?)?)|(S(EP?)?)|(O(CT?)?)|(N(OV?)?)|(D(EC?)?)))([ ](2(0\d{0,2})?)?)?)?)?)?)?)?$/;
	var theFullTest=RegExFullMiltaryDTG.test(testeChaine) && testeChaine.indexOf("00")!=0 && Number(testeChaine.substr(0,2))<32 && testeChaine.indexOf("24")!=2 && testeChaine.indexOf("0000")==-1 && !isNaN(Number(testeChaine.substr(0,6)));
	var dayOK=1;
	if (testeChaine.length>11) dayChecking(testeChaine);
	event.rc=theFullTest && dayOK;
} else {
	var RegExFullMiltaryDTG=/^(((0[1-9])|((1|2)\d)|(3[01]))(((0|1)\d)|(2[0-3]))([0-5]\d)[A-Z][ ]((JAN)|(FEB)|(MAR)|(APR)|(MAY)|(JUN)|(JUL)|(AUG)|(SEP)|(OCT)|(NOV)|(DEC))( 20)\d{2})?$/;
	var dayOK=1;
	if (RegExFullMiltaryDTG.test(event.value)) dayChecking(event.value);
	event.rc=dayOK;
}

 I did several tests and it seems that's working fine! Let me know if you catch some wrong examples.

The headache this script 😉

@+

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 30, 2022 Nov 30, 2022

Copy link to clipboard

Copied

Nice!

 

 

I see you had to use the splice method.

 

There was no way for me to figure oit a validation for just one letter and was shy of trying the .splice function.

 

Is it ok with you if I borrow some of your validations scripts and incorporate in mine?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 30, 2022 Nov 30, 2022

Copy link to clipboard

Copied

You can do whatever you want with the scripts I publish here!

They are free...

@+

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 30, 2022 Nov 30, 2022

Copy link to clipboard

Copied

aweosome ! thank you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Nov 30, 2022 Nov 30, 2022

Copy link to clipboard

Copied

Unsure where specifically in the script the [A-I,K-Z] needs to be added -- or if it's even the correct syntax for a script -- but in a DTG one of these letters is always used and corresponds to the time zone the report is being filled out in.  About 98% of the time, most will use Zulu (aka GMT) but occassionally, based on the COCOM or Fleet Commander's direction, they may be required to use the actual alphabetic time zone designator.  The designator falls right after the minutes and just before a space and then the month. Example in Zulu and quotes: ddHHMM"Z" mmm yyyy. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 30, 2022 Nov 30, 2022

Copy link to clipboard

Copied

++ Adding to Bebards' guidance,

 

The syntax is correct. 

 

The use of the brackets in RegEx identifies and instructs the script to evaluate a specific set.

[10] for example, is saying to match only a 0 or a 1.

 

While employing the use of a "dash" specifies to match any word character (in this case) from start to end in specifed range, for example. It  looks for and matches any upper case word characters from A through I and also from K through Z , that is why the use  of a comma is emplyed  inside of the brackets; it acts as an "OR" comparisson operator (if you may) when used inside of brackets. 

 

And all the parenthesis are used in Bebard's script to group specific patterns and try to match them before skipping to another comment.

 

 

If you're using the last script that he posted, look at the declared variable:

 

var RegExFullMiltaryDTG=/^(((0[1-9]?)|((1|2)\d?)|(3[01]?))((((0|1)\d?)|(2[0-3]?))([0-5]\d?)?([A-Z]([ ]((((J(AN?)?)|(F(EB?)?)|(M(AR?)?)|(A(PR?)?)|(M(AY?)?)|(J(UN?)?)|(J(UL?)?)|(A(UG?)?)|(S(EP?)?)|(O(CT?)?)|(N(OV?)?)|(D(EC?)?)))([ ](2(0\d{0,2})?)?)?)?)?)?)?)?$/;

 

And where it says [A-Z] change it to  [A-I,K-Z]

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 01, 2022 Dec 01, 2022

Copy link to clipboard

Copied

Hi,

Just a comment about the last point, you must write [A-IK-Z] without a comma between I and K else you allow to type a comma...

@+

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 01, 2022 Dec 01, 2022

Copy link to clipboard

Copied

Thank you for clarifying

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 01, 2022 Dec 01, 2022

Copy link to clipboard

Copied

The document level script and the FullDTG custom keystroke script ARE BRILLIANT!  THANK YOU!! 

For my own edification, is it possible for the one document level script to control both a full DTG and the Time/TimeZone only?  Or would it necessarily require two document level scripts?  In a reporting document, the DTG will inevitably be the primary document reference but within the reporting document the user may be reporting a specific time for an event. 

As I believe these scripts will quickly be snagged and propagate and I am a firm believer in the KISS (Keep It Simple Stuipd) principle, it would appear to me a single document level script would be the easiest -- more often the not, I am the reference point for the last "S" is the KISS principle. 😉 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 01, 2022 Dec 01, 2022

Copy link to clipboard

Copied

Hi,

A common document-level script would certainly be possible but also certainly a bit more complex.

At first glance it would be a combination of these 2 scripts that would run in accordance with the field name... I don't really understand the utility!

@+

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 02, 2022 Dec 02, 2022

Copy link to clipboard

Copied

Thank you.  I think I have learned more in just this thread from y'all than I have the entirety of the past 6 months of hunting the forums, cobbling together workable (at times only somewhat) solutions, or getting just the answers all of you Subject Matter Experts (SMEs) provide.  From what everyone here has provided, it seems to me that the custom keystroke scripts appear to be the best way to limit or prevent fatfingering while validation & format scripts appear best at ensuring "cooperation" with other fields and their associated scripts continue to work properly.  Would this be an accurate synopsis?  I may be oversimplifying things but I'm attempting to get my mind wrapped around the actual purposes of the varying methods of field control and you have provided the first keystroke script I have seen and/or used.  It works incredibly well and my mind races with possibilities where I could quite possibly have used it more effectively than some of the actions JS, validations, and calculation scripts I've implemented.  Especially where some reports have become rather slow due to the sheer volume of calculation scripts used.

My question regarding a common document-level script is in regards to some of my OPTESTing where I had multiple document level scripts running and they appeared to conflict with each other.  As I don't have the knowledge to de-conflict, I'd just diasable all those I didn't need at that point..  If I /* */ 'd a particular script or scripts out so I didn't have to delete it, leaving only one 'working', the one left active worked as advertised.  I was guessing there was some sort of conflict so am wondering that if an integrated document level script held the expressions for somewhat similiar fields it could work to limit the required amount of doc level scripts -- thereby  loading a single doc level script so multiple data fields could use its similiar but varying elements.

Again, just my mind wandering while trying to get a mental handle on all of this.  The majority of it sill seems like FM to me. 😉

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 09, 2022 Dec 09, 2022

Copy link to clipboard

Copied

Hi,

You reported a malfunction for my script:

quote
.. any time the DTG (full format ddHHMM(z) mmm yyyy) has a day (dd) entry of "10", "20", or "30", the script will not allow a time entry to exceed two (2) zeroes. So only the HH can contain 00 and then it will not allow a third zero as would be required within the first nine (9) minutes after midnight to 0009 (technically 0001 through 0009 as we've previously discussed there is no 0000 or 2400 used).

And effectively, it's a case I didn't think about!

Here is a new script which will solve this mistake:

if (!event.willCommit) {
	event.change=event.change.toUpperCase();
	if ((event.value.length==6 && event.selStart==6) || (event.selStart==6 && event.selEnd>7)) event.change+=" ";
	else if ((event.value.length==10 && event.selStart==10) || (event.selStart==10 && event.selEnd>11)) event.change+=" 20";
	var aTester=event.value.split("");
	aTester.splice(event.selStart, event.selEnd-event.selStart, event.change);
	var testeChaine=aTester.join("");
	var RegExFullMiltaryDTG=/^(((0[1-9]?)|((1|2)\d?)|(3[01]?))((((0|1)\d?)|(2[0-3]?))([0-5]\d?)?([A-Z]([ ]((((J(AN?)?)|(F(EB?)?)|(M(AR?)?)|(A(PR?)?)|(M(AY?)?)|(J(UN?)?)|(J(UL?)?)|(A(UG?)?)|(S(EP?)?)|(O(CT?)?)|(N(OV?)?)|(D(EC?)?)))([ ](2(0\d{0,2})?)?)?)?)?)?)?)?$/;
	var theFullTest=RegExFullMiltaryDTG.test(testeChaine) && testeChaine.indexOf("00")!=0 && Number(testeChaine.substr(0,2))<32 && testeChaine.indexOf("24")!=2 && (testeChaine.indexOf("0000")==-1 || (testeChaine.indexOf("0000")==1 && testeChaine.indexOf("00000")==-1)) && !isNaN(Number(testeChaine.substr(0,6)));
	var dayOK=1;
	if (testeChaine.length>11) dayChecking(testeChaine);
	event.rc=theFullTest && dayOK;
} else {
	var RegExFullMiltaryDTG=/^(((0[1-9])|((1|2)\d)|(3[01]))(((0|1)\d)|(2[0-3]))([0-5]\d)[A-Z][ ]((JAN)|(FEB)|(MAR)|(APR)|(MAY)|(JUN)|(JUL)|(AUG)|(SEP)|(OCT)|(NOV)|(DEC))( 20)\d{2})?$/;
	var dayOK=1;
	if (RegExFullMiltaryDTG.test(event.value)) dayChecking(event.value);
	event.rc=dayOK;
}

You should be able to write that case correctly now.

Capture d’écran 2022-12-09 à 10.39.11.png

Don't hesitate to tell me if you catch an other malfunction.

@+

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 12, 2022 Dec 12, 2022

Copy link to clipboard

Copied

LATEST

...and as required, here it is for only the time:

// Custom keystroke script
if (!event.willCommit) {
	var aTester=event.value.split("");
	aTester.splice(event.selStart, event.selEnd-event.selStart, event.change);
	var testeChaine=aTester.join("");
	var RegExTime=/^((((0|1)\d?)|([2][0-3]?))([0-5]\d?)?)?$/;
	event.rc=RegExTime.test(testeChaine) && testeChaine!="24" && Number(testeChaine.substr(2,1))<=5 && testeChaine!="0000";
} else {
	var RegExTime=/^(((0|1)\d)|([2][0-3]))([0-5]\d)$/;
	event.rc=event.value=="" || (RegExTime.test(event.value) && event.value!="0000");
}

// Validate script
event.rc=event.value=="" || (/^((((0|1)\d)|([2][0-3]))([0-5]\d))?$/.test(event.value) && event.value!="0000");

@+

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines