unrecognizable email address from javascript validation -
i have script written long ago freelancer that's worked fine until now. script checks email address form against matching rules , returns true/false. problem reason isn't recognizing email address has simple firstinitiallastname@domain.com syntax (no periods or characters, etc).
i don't understand javascript understand php if tell me why script return false against email address formatted indicated above, i'd appreciate it.
function check_email(str) { var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-za-z]{2,7}$/; if (!str.match(re)) { return false; } else { return true; } }
it should work, regexp valid.
are sure email trimmed of spaces @ end/beginning? if leave trailing space @ end or hanging 1 @ beginning won't work accepts alphanumeric characters @ beginning , a-za-z characters @ end (domain). whitespace thing can come can break it.
and refactor bit , shorten return match value returns array of matches or null (which equals false in comparisions)
function check_email(str) { return str.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-za-z]{2,7}$/); }
Comments
Post a Comment