1 Reply Latest reply on Sep 30, 2014 8:02 PM by George_Johnson

    JavaScript E-mail Validation Script Issues

    tbermeo

      Hi Everyone:

       

      I am using Adobe Pro. I'm looking to validate a custom textbox I created which will contain email addresses, for example:

      xxx@xxx.xxx; xxx@xxx.xxx; xxx@xxx.xxx

      I wrote some JavaScript which looks to be accurate, however It's not working. Can anyone make mention to something I am doing wrong here? It looks to get hung up when I attempt to parse into array.

       

      if (event.value!=null){
           var values = event.value;
           var valueInfo = values.toString();
           var emailArray = valueInfo.Split(';');
        
      $.each(emailArray, function(i,val){
           if(!eMailValidate(val)){
           app.alert("Incorrect Format");
           event.rc = false;
           }
         });
      }
      
      

       

      thanks in advance.

       

       

      Tony

        • 1. Re: JavaScript E-mail Validation Script Issues
          George_Johnson MVP & Adobe Community Professional

          If this is a validate script, there are several problems with it. First of all, event.value will always be a string, so it will never be equal to the the special value null. To test for a zero-length string, compare it to one:

           

          if (event.value !== "") {

           

          or better yet:

           

          if (event.value) {

           

           

          This means you don't have to use the toString method to convert it to a string, since it always will be one.

           

          The split string method is not capitalized, so valueInfo.Split is not correct.

           

          Assuming you didn't somehow incorporate JQuery or something similar, the following line isn't valid:

           

          $.each(emailArray, function(i,val){ 

           

           

          Use a simple for loop instead.