Skip to content

Instantly share code, notes, and snippets.

@cgkio
Created December 11, 2013 19:53
Show Gist options
  • Save cgkio/7917255 to your computer and use it in GitHub Desktop.
Save cgkio/7917255 to your computer and use it in GitHub Desktop.
Validate email address using REGEX
var $email = $('form input[name="email'); //change form to id or containment selector
var re = /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/igm;
if ($email.val() == '' || !re.test($email.val()))
{
alert('Please enter a valid email address.');
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment