Skip to content

Instantly share code, notes, and snippets.

@azeemhassni
Last active August 29, 2015 14:01
Show Gist options
  • Save azeemhassni/d4d7bee79373b129d3f9 to your computer and use it in GitHub Desktop.
Save azeemhassni/d4d7bee79373b129d3f9 to your computer and use it in GitHub Desktop.
Email Validation Regular Expression
// ^([0-9a-zA-Z\._])+@([a-zA-Z0-9])+\.([0-9A-Za-z]){2,4}([\.a-zA-Z0-9]){0,3}+$
// example : (jQuery) Javascript
function validateEmail(email){
var pattren = new RegExp("^([0-9a-zA-Z\._])+@([a-zA-Z0-9])+\.([0-9A-Za-z]){2,4}([\.a-zA-Z0-9]){0,3}+$");
if(pttren.test(email)){
return true;
} else
return false;
}
jQuery(function(){
$("yourform").submit(function(){
var email = $("emailField").val();
if(!validateEmail(email)){
e.preventDefault();
alert("Please Enter a valid email");
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment