Not sure if there is a solution available but not able to find. So asking it again.
I am writing an email validator. This should validate all well formed email(This is just one level of validation to check the email is well formed). Now as my code is an international code so i should support non latin characters also. How do i write the most efficient Regex for that?
International Emails: http://en.wikipedia.org/wiki/International_email
Some example emails:
It should be able to validate all the above formats
Regex provides the ability to validate the structure of an email address.
[a-zA-Z0-9+_. -] matches one character from the English alphabet (both cases), digits, “+”, “_”, “.” and, “-” before the @ symbol. + indicates the repetition of the above-mentioned set of characters one or more times. @ matches itself.
The best all-around regex to find valid email addressesallows Latin characters ("a" - "z" or "A" - "Z") within the email address. permits digits (0 - 9) in the email address. enforces domain part restrictions. allows hyphens (-) inside the domain as long as they don't lead or trail the domain.
The reason why email validation through regexp is so lax is because it's not efficient. There is a spec for email address syntax, but the regexp to check it is so long, it's impractical. Besides, email providers are more strict in their implementation of the syntax than the actual spec. An email might be considered valid as the spec says it is, but invalid according to the provider.
That's also the reason why activation emails exist, because the only way to check if an email is valid, existing and currently in use is to send it something, usually a unique activation code or link. Only when that unique activation code or link, only sent to that email, is used will the email be considered valid.
Until then, consider a more lax approach in validating emails, checking if the username, the @
and the domain parts. Besides, why would one sign up using a false email anyway? If they did, they wouldn't get the activation link, and can't proceed creating the account.
@Patashu Thanks a lot. I've improved your regex a bit and now it's absolutely suits my needs:
^([^@\s\."'\(\)\[\]\{\}\\/,:;]+\.)*[^@\s\."'\(\)\[\]\{\}\\/,:;]+@[^@\s\."'\(\)\[\]\{\}\\/,:;]+(\.[^@\s\."'\(\)\[\]\{\}\\/,:;]+)+$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With