commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mr...@apache.org
Subject cvs commit: jakarta-commons/validator/src/javascript/org/apache/commons/validator/javascript validateEmail.js
Date Sat, 12 Jun 2004 00:31:02 GMT
mrdon       2004/06/11 17:31:02

  Modified:    validator/src/javascript/org/apache/commons/validator/javascript
                        validateEmail.js
  Log:
  Updated js email validation from referenced source script
  PR: 29532
  Obtained from: http://javascript.internet.com/forms/email-address-validation.html
  
  Revision  Changes    Path
  1.10      +61 -49    jakarta-commons/validator/src/javascript/org/apache/commons/validator/javascript/validateEmail.js
  
  Index: validateEmail.js
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/validator/src/javascript/org/apache/commons/validator/javascript/validateEmail.js,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- validateEmail.js	28 Mar 2004 16:53:21 -0000	1.9
  +++ validateEmail.js	12 Jun 2004 00:31:02 -0000	1.10
  @@ -1,5 +1,5 @@
   
  -   /*$RCSfile$ $Revision$ $Date$ */
  +    /*$RCSfile$ $Revision$ $Date$ */
       /**
       * Check to see if fields are a valid email address.
       * Fields are not checked if they are disabled.
  @@ -44,51 +44,63 @@
        * http://javascript.internet.com
        */
       function checkEmail(emailStr) {
  -       if (emailStr.length == 0) {
  -           return true;
  -       }
  -       var emailPat=/^(.+)@(.+)$/;
  -       var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
  -       var validChars="\[^\\s" + specialChars + "\]";
  -       var quotedUser="(\"[^\"]*\")";
  -       var ipDomainPat=/^(\d{1,3})[.](\d{1,3})[.](\d{1,3})[.](\d{1,3})$/;
  -       var atom=validChars + '+';
  -       var word="(" + atom + "|" + quotedUser + ")";
  -       var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
  -       var domainPat=new RegExp("^" + atom + "(\\." + atom + ")*$");
  -       var matchArray=emailStr.match(emailPat);
  -       if (matchArray == null) {
  -           return false;
  -       }
  -       var user=matchArray[1];
  -       var domain=matchArray[2];
  -       if (user.match(userPat) == null) {
  -           return false;
  -       }
  -       var IPArray = domain.match(ipDomainPat);
  -       if (IPArray != null) {
  -           for (var i = 1; i <= 4; i++) {
  -              if (IPArray[i] > 255) {
  -                 return false;
  -              }
  -           }
  -           return true;
  -       }
  -       var domainArray=domain.match(domainPat);
  -       if (domainArray == null) {
  -           return false;
  -       }
  -       var atomPat=new RegExp(atom,"g");
  -       var domArr=domain.match(atomPat);
  -       var len=domArr.length;
  -       if ((domArr[domArr.length-1].length < 2) ||
  -           (domArr[domArr.length-1].length > 3)) {
  -           return false;
  -       }
  -       if (len < 2) {
  -           return false;
  -       }
  -       return true;
  -    }
  -
  -  
  \ No newline at end of file
  +        if (emailStr.length == 0) {
  +            return true;
  +        }
  +        // TLD checking turned off by default
  +        var checkTLD=0;
  +        var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
  +        var emailPat=/^(.+)@(.+)$/;
  +        var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
  +        var validChars="\[^\\s" + specialChars + "\]";
  +        var quotedUser="(\"[^\"]*\")";
  +        var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
  +        var atom=validChars + '+';
  +        var word="(" + atom + "|" + quotedUser + ")";
  +        var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
  +        var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
  +        var matchArray=emailStr.match(emailPat);
  +        if (matchArray==null) {
  +            return false;
  +        }
  +        var user=matchArray[1];
  +        var domain=matchArray[2];
  +        for (i=0; i<user.length; i++) {
  +            if (user.charCodeAt(i)>127) {
  +                return false;
  +            }
  +        }
  +        for (i=0; i<domain.length; i++) {
  +            if (domain.charCodeAt(i)>127) {
  +                return false;
  +            }
  +        }
  +        if (user.match(userPat)==null) {
  +            return false;
  +        }
  +        var IPArray=domain.match(ipDomainPat);
  +        if (IPArray!=null) {
  +            for (var i=1;i<=4;i++) {
  +                if (IPArray[i]>255) {
  +                    return false;
  +                }
  +            }
  +            return true;
  +        }
  +        var atomPat=new RegExp("^" + atom + "$");
  +        var domArr=domain.split(".");
  +        var len=domArr.length;
  +        for (i=0;i<len;i++) {
  +            if (domArr[i].search(atomPat)==-1) {
  +                return false;
  +            }
  +        }
  +        if (checkTLD && domArr[domArr.length-1].length!=2 && 
  +            domArr[domArr.length-1].search(knownDomsPat)==-1) {
  +            return false;
  +        }
  +        if (len<2) {
  +            return false;
  +        }
  +        return true;
  +    }
  \ No newline at end of file
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message