Categories
Uncategorized

How to validate email address using regex in javascript / jquery ?

Code on jsbin : http://jsbin.com/ozeyag/19/edit
Live Demo : http://jsbin.com/ozeyag/19/

function validateEmail(email) {
var re = /^(([^<>()[]\.,;:s@"]+(.[^<>()[]\.,;:s@"]+)*)|(".+"))@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}])|(([a-zA-Z-0-9]+.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
function validate(){
var email = $("#email").val();
if (validateEmail(email)) {
// email is valid
}
else {
// email is invalid.
}
return false;
}
Reference :
StackOverflow : Validate email address in Javascript ?
Hope this helped you. Cheers ! :)