Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

EhteshamMehmood commented Mar 26, 2017

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

@webdevium

This comment has been minimized.

Copy link

webdevium commented Sep 6, 2017

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

@peterschristoph

This comment has been minimized.

Copy link

peterschristoph commented Feb 12, 2018

@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
You can’t perform that action at this time.