Skip to content

Instantly share code, notes, and snippets.

@fakiolinho
Last active March 25, 2022 05:47
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save fakiolinho/5438830 to your computer and use it in GitHub Desktop.
Save fakiolinho/5438830 to your computer and use it in GitHub Desktop.
jQuery: Validate Email with Regex
/* jQuery Validate Emails with Regex */
function validateEmail(Email) {
var pattern = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
return $.trim(Email).match(pattern) ? true : false;
}
@EhteshamMehmood
Copy link

jQuery Email Validation using Regex Expression. you can use for PHP, ASP
http://www.phpcodify.com/jquery-email-validation-using-regex-expression/

@vanodevium
Copy link

return pattern.test($.trim(email)); is more adequate solution.

@peterschristoph
Copy link

@EhteshamMehmood, your code/demo on phpcodify allows invalid emails.

For example, you allow some email beginning with a dot.
phpcodify_mail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment