Skip to content

Instantly share code, notes, and snippets.

@0632347878
Created December 13, 2018 21:53
Show Gist options
  • Save 0632347878/cf117083077e9dc2ed42169a35185343 to your computer and use it in GitHub Desktop.
Save 0632347878/cf117083077e9dc2ed42169a35185343 to your computer and use it in GitHub Desktop.
validate email
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 $result = $("#result");
var email = $("#email").val();
$result.text("");
if (validateEmail(email)) {
$result.text(email + " is valid :)");
$result.css("color", "green");
} else {
$result.text(email + " is not valid :(");
$result.css("color", "red");
}
return false;
}
$("#validate").bind("click", validate);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment