froatsnook:valid-email

v1.0.0Published 9 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

This package implements ValidEmail using Match.Where. This means that you can use:

1check(email, ValidEmail);

and:

1if (Match.test(email, ValidEmail)) {
2    // ...
3}

For code clarity it also provides IsValidEmail:

1if (IsValidEmail(email)) {
2    // ...
3}

By default, a very basic regexp is used:

1ValidEmail.regex = /^[A-Z0-9\._%+-]+@[A-Z0-9\.-]+\.[A-Z]{2,}$/i;

But you can change the value of ValidEmail.regex to suit your needs.

Some extra regexps are provided:

1// /^[^@]+@[^@]+$/;
2ValidEmail.regex = ValidEmail.permissive;

And if you wanted to follow the rfc you could do this:

1// from http://badsyntax.co/post/javascript-email-validation-rfc822
2ValidEmail.regex = /^([^\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))*$/;