4 Replies Latest reply on May 21, 2012 11:17 AM by 01371406

    Company email address

    01371406 Level 1

      I need to verify an entered email address on a PDF is a company only email address inputed. No gmail, yahoo or other types of email address should be accepted.

       

      For example I need the only valid email addresses to be accepted:

      *@companyname.com

       

      Should I use a truncate function to compare values or is there a better way to validate this field? To clarify I don't care if the email address is a valid company email address. Just so that it ends with @companyname.com

       

      Thanks.

        • 1. Re: Company email address
          George_Johnson MVP & Adobe Community Professional

          A custom Validate script for the field could look like:

           

          // Custom Validate script

          (function () {

           

              var sDomain = "example.com";

           

              // Don't do anything if field is blank
              if (!event.value) return;

           

              // Get the domain of the entered address, if any
              var sEnteredDomain = event.value.split("@")[1];

           

              if (typeof sEnteredDomain === "undefined" || sEnteredDomain.toLowerCase() !== sDomain) {

                  // Reject the entry
                  event.rc = false;

                  // Alert the user
                  app.alert("Please enter a valid email address.\r\rDomain must be: " + sDomain, 3);
              }

           

          })();

          • 2. Re: Company email address
            01371406 Level 1

            Thanks George. I am having some problem translating this code into my PDF. I am new to programing javascript and in Acrobat. I don't understand where my field name ("Email") goes to account for the field haivng the script validate the email. I thought substituting the word Email for !event and later on in the code Email for event would suffice. That is not working however. Any suggestions? Thanks for your response.

            • 3. Re: Company email address
              George_Johnson MVP & Adobe Community Professional

              You don't have to change anything apart from the sDomain variable and the text of the error message you want to use. It will work with any field name, just place the entire script in the Validate event of the field.

              • 4. Re: Company email address
                01371406 Level 1

                That cleared it up. I didn't realize it had to be entered as a "Custom Validate" script and not in the "Actions" tab. Thanks again.