Tuesday, October 16, 2012

Email Validation using JavaScript & Regular expressions

The Email validation for the 2,3,4 digit suffixes can be implemented using the following regular expression. 


function IsValidEmail(e) {
        var alnum = "a-zA-Z0-9";        
        exp = /^[a-zA-Z0-9._]+[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z]{2,4}$/;
        emailregexp = new RegExp(exp);

        result = e.match(emailregexp);
        if (result != null) {
            return true;
        }
        else {
                 return false;
        }
    }

Use the above code to validate the email.

No comments:

Post a Comment