4 Replies Latest reply on Nov 23, 2015 6:13 AM by Geckoz100

    Simple email validation in forms

    Andrew Smith 12

      Hello All,

       

      I would like to do a simple email validation, the built in email validation pattern(text{OOOOOOOO'@example.com'} ) is not really useful.

       

      What is the best to validate an email in the form which was built using livecycle designer.

       

      Is there any other pattern I can use?

       

      My requirement is simple, the email should contain ‘@’ and a dot, something like ( xxx@xxx.xxx)

       

      Any help is much appreciated.

       

      Thanks and regards,

       

        • 1. Re: Simple email validation in forms
          Andrew Smith 12 Newcomer

          I manage to solve the problem.

           

          It is simple use the custom email address control.

           

          Alternatively place the following javascript in normal textbox control.

           

          // Validate the email address.

           

          var

           

          r = new RegExp("^[a-z0-9_\\-\\.]+\\@[a-z0-9_\\-\\.]+\\.[a-z]{2,3}$"); // Create a new Regular Expression Object.

          // Set the regular expression to look for an email address in general form.

           

          var

           

          result = r.test(this.rawValue); // Test the rawValue of the current object to see

           

           

          // if it fits the general form of an email address.

           

          if

           

          (result == true) // If it fits the general form,

           

           

            true; // all is well.

          else

           

          // Otherwise,

           

           

            false; // fail the validation.

          • 2. Re: Simple email validation in forms
            Tav Campbell

            Thanks for posting this

            • 3. Re: Simple email validation in forms
              Geckoz100 Newcomer

              Perfect -- works like a charm! (LCD ES2).

               

              One question:  is there any way to make the focus stay on the e-mail field?  Because once it produces an error message due to invalid e-mail format, the focus moves to the next field anyway.

              • 4. Re: Simple email validation in forms
                Geckoz100 Newcomer

                I added a couple of tweaks -- (1) to allow for up to 8-character domain suffixes (there are some long ones out there -- "museum", "travel", etc.);  (2) allows the user to leave the field empty with the initial if statement;  (3) if the field has content, the focus stays on the field if there's a validation error.  Thanks to OP Andrew Smith for the script.

                 

                if (this.rawValue != null) {
                     // Create a new Regular Expression Object
                     var r = new RegExp("^[a-z0-9_\\-\\.]+\\@[a-z0-9_\\-\\.]+\\.[a-z]{2,8}$"); // (allows 2-8 characters in domain suffix)
                     // Set the regular expression to look for an email address in general form
                     // Test the rawValue of the current object to see if it fits the general form of an email address
                     var result = r.test(this.rawValue);
                     if (result == false)  {
                          xfa.host.messageBox("Invalid e-mail address -- please use format username@domain.xxx","CHECK E-MAIL FORMAT",0,0);
                          xfa.host.setFocus(this);
                }