8 Replies Latest reply on Jan 9, 2015 10:10 AM by try67

    Date Validation

    bethg44

      Would like the user to entire mm/dd/yy in the text field. However, I do not want the user to be able to type any letters at all into the date field. I know if I use the "Format-->Date" under the field properties, it will still allow me to type letters in the field but will throw an exception. I want to permit this (letters being entered). I still would like an error message thrown if date is not entered correctly.

       

      Please help! Thanks!!! :-)

        • 1. Re: Date Validation
          gkaiseril MVP & Adobe Community Professional

          You need to select more than "Format => Date" for selecting a date format. If one selects the option "mm/dd/yyyy" one can only enter numeric values and the "/" separator.

           

          One needs to write a custom keystroke, format, and validation script for your format choice and it needs to be the "Custom" format and not the "Custom" under the date.  And I do not have an example handy right now.

          • 2. Re: Date Validation
            bethg44 Level 1

            gkaiseril Correct, I chose the mm/dd/yy under Format---> Date and the user can still enter alphanumeric (even though it will throw an error message), the client I am working for does not want the user at all to enter any letters.

             

            Any help is appreciated!!

            • 3. Re: Date Validation
              try67 MVP & Adobe Community Professional

              If you want to have that feature then you can't use the built-in Date format. You'll need to create your own custom keystroke and validation scripts to achieve it.

              • 4. Re: Date Validation
                bethg44 Level 1

                Thats correct, I am wondering if I can get help on setting up a custom keystroke/custom format :/ I am not the best when it comes to Reg Expressions. Still learning :/

                • 5. Re: Date Validation
                  Dan J Williams Level 1

                  Hi Beth, try this for your Custom Validation script:

                  var v = event.value;

                  var d = util.scand("mm/dd/yy", v);

                  if (d == null) {

                      event.value = "";

                      app.alert("Invalid date. Please check and re-enter (mm/dd/yy).");

                  }

                   

                  Then add an Arbitrary Mask under the field's Format > Special section.

                  99/99/99

                   

                  The 9's indicate where you want a numeric to appear, the / signifies the spacer. You can make it 99-99-99 if you wish to format it that way.

                   

                  This validation type will ONLY allow a numeric string to be entered. E.g. 100604

                  The in-built 'Date' validation is much better and accepts a larger range of data inputs which will cater for a larger range of users. See an example PDF here: https://dl.dropboxusercontent.com/u/48690130/DateFormatTest.pdf

                  • 6. Re: Date Validation
                    bethg44 Level 1

                    Awesome! Thanks for the information :-)

                    • 7. Re: Date Validation
                      Geckoz100 Level 1

                      Can I use this in LiveCycle Designer ES2?  I would like to let the user enter a date using numbers only, and have the field add in slashes as needed, in addition to validating for a proper date.  I have the script below that I used for a PDF form in Acrobat X, but it doesn't work when I enter it in the Javascript editor in ES2.  Thanks for any assistance.

                       

                      //Acrobat date validation

                      //Custom Validation Java Script for entering dates using numbers only

                      //courtesy of Ricardo Falegnami

                       

                      // adding slashes

                      var newDate = event.value;

                      // validate date

                      if (newDate != "") { // process non-empty string

                          var oMyDate = [];

                       

                       

                          oMyDate[0] = util.scand("mmddyyyy", newDate);

                          oMyDate[1] = util.scand("mmddyy", newDate);

                          oMyDate[2] = util.scand("mddyyyy", newDate);

                          oMyDate[3] = util.scand("mmdyyyy", newDate);

                          oMyDate[4] = util.scand("mdyyyy", newDate);

                          oMyDate[5] = util.scand("mdyy", newDate);

                          var isDate = false;

                       

                       

                          for (var i=0; i<oMyDate.length; i++) {

                              if (oMyDate[i] !== null) {

                                  event.value = util.printd("mm/dd/yyyy", oMyDate[i]); // strict format

                                  isDate = true;

                                  break;

                              }

                          }

                       

                       

                      // Stay in field if invalid

                          if (isDate === false) {

                              app.alert("Invalid date entered -- please use MMDDYYYY (e.g., 10152014)", 0, 1, "Date Validation"); // check validity

                              event.value = "";

                              event.target.setFocus();

                          }

                      }

                      • 8. Re: Date Validation
                        try67 MVP & Adobe Community Professional

                        No, the scripting language within LCD forms is different in some ways than

                        that in Acrobat forms.

                        You should ask over at the LCD forum for more information about how to

                        implement it in these files.