Monday, June 4, 2012

Simple email validation using JS



function validEmail(e) {
    var filter = /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/;
    if(filter.test(e)){alert("valid email")}
  else{alert("invalid email")}

}


this code will throw false for any invalid email address. This code checks validity with respect to what is email pattern and what are permissible characters