13 Replies Latest reply on Jun 9, 2011 1:36 PM by bcjohn1

    Default Form Validation Message

    bcjohn1

      I can't seem to figure out how to use Adobe built in formatting, but write my own error messages. The default message for date and phone validation is, "The value entered does not match the format of the field [ field_name ]". How do I use the built in validation, but overwrite this default message?

       

      Thanks to all for any assistance or direction pointing.

        • 1. Re: Default Form Validation Message
          gkaiseril MVP & Adobe Community Professional

          If you created the form in Adobe Acrobat, not LiveCycle Designer, you can use the 'Custom Calculation Script" on the "Validate" tab for the field's properties to write your own validation script.

           

          From the text of the message and experience I would guess you have a script or calculation that is performing a division operation. Division by zero will through an error if the result is being placed into a field that has the numeric format. In this situation, it is best to write a custom calculation script and not perform the division when the divisor is zero.

          1 person found this helpful
          • 2. Re: Default Form Validation Message
            bcjohn1 Level 1

            Much obliged for the quick responce. So the answer is there isn't a way to do this without writing my own validation? Does LiveCycle allow me to modify the default alert message while useing the built in validation?

            • 3. Re: Default Form Validation Message
              bcjohn1 Level 1

              I should have been more specific. There are no calculations involved. Just a field format requiring user input to be in (111) 111-1111 format for phone number, and mm/dd/yyy for date.

               

              This is easily done, but I can't control the alert messagebox that pops up when the input isn't valid.

              • 4. Re: Default Form Validation Message
                gkaiseril MVP & Adobe Community Professional

                You will still have to write a custom validation script.

                 

                You might also want to write custom keystroke and format scripts as you can provide more flexibility in to the data entry. This could include the optional entry and what characters could be used as separators.

                • 5. Re: Default Form Validation Message
                  bcjohn1 Level 1

                  Here's what I have so far:

                   

                  var home_phone=this.getField("home_phone");
                  var string=home_phone.value.toString();
                  var length=string.length;
                  var number;

                   

                    if(length != 10)
                    {
                      app.alert("Enter a valid 10 digit number.");
                      number="";
                    }
                    else
                    {
                      number="(";
                      var ini = string.substring(0,3);
                      number+=ini+")";
                      var st = string.substring(3,6);
                      number+=st+"-";
                      var end = string.substring(6,10);
                      number+=end;
                    }
                   
                    home_phone.value=number;

                   

                  This will reformat a number like this 1234567890 to this (123)456-7890 allowing me to control the alert message myself. However if the user enters the number in the correct format this code won't accept that as valid input. How can I allow input in the correct format?

                   

                  Thanks!

                  • 6. Re: Default Form Validation Message
                    gkaiseril MVP & Adobe Community Professional

                    The default special format for numbers accepts:

                     

                    1111111111

                    111 111 1111

                    (111) 111 1111

                    111-111-1111

                    (111) 111-1111

                    (111)-111-1111

                    111.111.1111

                     

                    So this is far more complex than what you have assumed.

                     

                    The above values and other are evaluated using the RegExp object to evaluate all the possible entry formats.

                     

                     

                    In the 'Custom Validation Script' you could use:

                     

                     

                      if(event.value.length != 10)
                      {
                        app.alert("Enter a valid 10 digit number.");
                        event.number = "";

                       app.alert("enter the 10 digit phone number without separators", 2, 0, "Invalid Entry");

                        event.rc = false;

                      }

                    If you want to allow for more input options, you will need to write custom keystroke, format, and validation scripts using the RegExp to sort out the valid keystrokes and format the inputted value as you want it displayed.

                    1 person found this helpful
                    • 7. Re: Default Form Validation Message
                      gkaiseril MVP & Adobe Community Professional

                      For North American Phone Numbers, the following custom scripts can be used for keystroke, formatting, and validation using the RegExp object.


                      // custom format
                      var re_NA_Phone_Commit = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/
                      if(re_NA_Phone_Commit.test(event.value)) 
                      event.value = "("+ RegExp.$1 +") " + RegExp.$2 + "-" + RegExp.$3;
                      else {
                      event.value = "";
                      event.rc = false;
                      }
                      // end custom format


                      // custom format
                      var re_NA_Phone_Commit = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/
                      if(re_NA_Phone_Commit.test(event.value)) 
                      event.value = "("+ RegExp.$1 +") " + RegExp.$2 + "-" + RegExp.$3;
                      else {
                      event.value = "";
                      event.rc = false;
                      }
                      // end custom format


                      // custom validation script;
                      var re_NA_Phone_Commit = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/
                      if(re_NA_Phone_Commit.test(event.value) == false) {
                      app.beep();
                      app.alert("Please enter a 10 digit phone number", 1, 0, "Phone Number");
                      event.rc = false;
                      }
                      // end custom format;


                      The above script could be extended to include valid phone number range for the following construction:

                      •    Area codes start with a number from 2-9, followed by 0-8, and then any third digit.
                      •    The second group of three digits, known as the central office or exchange code, starts with a number from 2-9, followed by any two digits.
                      •    The final four digits, known as the station code, have no restrictions

                       

                      One could also allow for a leading '1' or '1+'.'

                      • 8. Re: Default Form Validation Message
                        bcjohn1 Level 1

                        This looks like it will do exactly what I need. However I don't see where my users input comes into this? Where is the variable containing the numbers input into the form? These are the numbers I need to check and or format. Maybe event.value is my users form input? I'm almost there, but not quite getting the whole picture.

                        • 9. Re: Default Form Validation Message
                          bcjohn1 Level 1

                          With your most excellent and admirable assistance I was able to get this working exactly as I need it too!!

                           

                          I replaced "event" with the input telephone value, and it works flawlessly. I can't thank you enough for your help here.

                           

                          This is my final code:

                           

                          // custom format
                          var home_phone=this.getField("home_phone");

                           

                          var re_NA_Phone_Commit = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/
                          if(re_NA_Phone_Commit.test(home_phone.value))
                          home_phone.value = "("+ RegExp.$1 +") " + RegExp.$2 + "-" + RegExp.$3;
                          else {
                          home_phone.value = "";
                          home_phone.rc = false;
                          }
                          // end custom format

                           


                          // custom format
                          var re_NA_Phone_Commit = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/
                          if(re_NA_Phone_Commit.test(home_phone.value))
                          home_phone.value = "("+ RegExp.$1 +") " + RegExp.$2 + "-" + RegExp.$3;
                          else {
                          home_phone.value = "";
                          home_phone.rc = false;
                          }
                          // end custom format

                           


                          // custom validation script;
                          var re_NA_Phone_Commit = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/
                          if(re_NA_Phone_Commit.test(home_phone.value) == false) {
                          app.beep();
                          app.alert("Please enter a 10 digit phone number", 1, 0, "Phone Number");
                          home_phone.rc = false;
                          }
                          // end custom format;

                          • 10. Re: Default Form Validation Message
                            bcjohn1 Level 1

                            I now need to apply this to date formatting and validation. I need to insert backslashes after two characters then five characters as in mm/dd/yyyy. However I also need to check what the user input looks like, and not perform formatting if the input is of a valid date format.

                             

                            I now see where to enter the Custom Format Script, Custom Keystroke Script, and custom validation script. Previously I was entering everything into a Javascript run onBlur();

                             

                            Here's what I've been trying so far:

                             

                            //var dateStr = this.rawValue;
                            var regExp = /^(\d{1,2})[./-](\d{1,2})[./-](\d{2})$/

                             

                            if (regExp.test(event.rawValue) == false) {

                             

                            app.alert("Please enter the date in the format MM/DD/YYYY.");
                            //this.setFocus();
                            //event.value="";
                            event.rs = false;
                            }

                             

                            This is starting to work, but isn't quite there yet.

                            • 11. Re: Default Form Validation Message
                              bcjohn1 Level 1

                              Here's what I've come up with. It works well, but doesn't do all the fancy reformatting that I'd like. If anyone has input here it'd be appreciated. Otherwise here's what we came up with.

                               

                              var Date=this.getField("date");
                              var regExp = /^((0?[1-9]|1[012])[- /.](0?[1-9]|[12][0-9]|3[01])[- /.](19|20)?[0-9]{2})*$/

                               

                              if(!regExp.test(Date.value)){
                              app.alert("Please enter the date in the format MM/DD/YYYY.");
                              Date.value="";
                              Date.setFocus();
                              }

                               

                              Thanks to the community here!

                              • 12. Re: Default Form Validation Message
                                gkaiseril MVP & Adobe Community Professional

                                Dates are even more difficult because there are not only more options on how to enter the various elements and arrange the various elements and since some to elements can not be uniquely identified by the entry you should consider a different approach than the RegExp. Month and day order and values can not always be a determinate as the free entry of these values.

                                 

                                I would start with instructions on the form as to the expected entry format.

                                 

                                If you feel you absolutely need a date validation, I would look at the date handling features for dates. You can us the 'scand()' method and 'Date()' constrictor to verify if a date not only matches a required format, but is also a valid date.

                                 

                                Since this item is marked answered, You might not get a lot new respondents.

                                • 13. Re: Default Form Validation Message
                                  bcjohn1 Level 1

                                  I think I'll leave my validation as is using regular expressions, and not get into managing user input beyond that.

                                   

                                  I did wonder whether I should start a new topic with this question, but opted to keep from opening up a new post because of the lower priority since I do have code that works fairly well for my purposes.

                                   

                                  Thanks again, and keep up the good work!