Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
rfc822 email validation in JS
// See http://rosskendall.com/blog/web/javascript-function-to-check-an-email-address-conforms-to-rfc822
function isEmail(email){
return /^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$/.test( email );
}
@jhyland87

This comment has been minimized.

Show comment Hide comment
@jhyland87

jhyland87 Jan 24, 2016

Why is this so different (much shorter) than the other RFC822 patterns ive found? here or here for example? (Granted, those two dont seem to work with JS regex validators such as match or test... so I like yours)

Why is this so different (much shorter) than the other RFC822 patterns ive found? here or here for example? (Granted, those two dont seem to work with JS regex validators such as match or test... so I like yours)

@Leonid-Yeromin

This comment has been minimized.

Show comment Hide comment
@Leonid-Yeromin

Leonid-Yeromin Jun 26, 2017

Passes unicode like: あいうえお@domain.com

Passes unicode like: あいうえお@domain.com

@Leonid-Yeromin

This comment has been minimized.

Show comment Hide comment
@Leonid-Yeromin

Leonid-Yeromin Jun 26, 2017

and this:
'email@-domain.com',
'email@domain.web',
'email@111.222.333.44444',

and this:
'email@-domain.com',
'email@domain.web',
'email@111.222.333.44444',

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