How should I validate an e-mail address?

Another option is the built in Patterns starting with API Level 8: public final static boolean isValidEmail(CharSequence target) { if (TextUtils.isEmpty(target)) { return false; } else { return android.util.Patterns.EMAIL_ADDRESS.matcher(target).matches(); } } Patterns viewable source OR One line solution from @AdamvandenHoven: public final static boolean isValidEmail(CharSequence target) { return !TextUtils.isEmpty(target) && android.util.Patterns.EMAIL_ADDRESS.matcher(target).matches(); }

How to validate an Email in PHP?

You can use the filter_var() function, which gives you a lot of handy validation and sanitization options. filter_var($email, FILTER_VALIDATE_EMAIL) PHP Manual filter_var() Available in PHP >= 5.2.0 If you don’t want to change your code that relied on your function, just do: function isValidEmail($email){ return filter_var($email, FILTER_VALIDATE_EMAIL) !== false; } Note: For other uses (where … Read more

What characters are allowed in an email address?

See RFC 5322: Internet Message Format and, to a lesser extent, RFC 5321: Simple Mail Transfer Protocol. RFC 822 also covers email addresses, but it deals mostly with its structure: addr-spec = local-part “@” domain ; global address local-part = word *(“.” word) ; uninterpreted ; case-preserved domain = sub-domain *(“.” sub-domain) sub-domain = domain-ref … Read more

What’s the best way to validate an email address in JavaScript?

Using regular expressions is probably the best way. You can see a bunch of tests here (taken from chromium) const validateEmail = (email) => { return String(email) .toLowerCase() .match( /^(([^<>()[\]\\.,;:\s@”]+(\.[^<>()[\]\\.,;:\s@”]+)*)|(“.+”))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ ); }; Here’s the example of a regular expression that accepts unicode: const re = /^(([^<>()[\]\.,;:\s@\”]+(\.[^<>()[\]\.,;:\s@\”]+)*)|(\”.+\”))@(([^<>()[\]\.,;:\s@\”]+\.)+[^<>()[\]\.,;:\s@\”]{2,})$/i; But keep in mind that one should not rely … Read more

How can I validate an email address using a regular expression?

The fully RFC 822 compliant regex is inefficient and obscure because of its length. Fortunately, RFC 822 was superseded twice and the current specification for email addresses is RFC 5322. RFC 5322 leads to a regex that can be understood if studied for a few minutes and is efficient enough for actual use. One RFC … Read more

tech