Created
December 13, 2018 21:53
-
-
Save 0632347878/cf117083077e9dc2ed42169a35185343 to your computer and use it in GitHub Desktop.
validate email
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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