Link to home
Create AccountLog in
Avatar of johnson1
johnson1

asked on

check for valid email

Hello,
Can you please help me find regex that I can use to check for valid email?
Greetings,
Skúli
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

as a start, try look for:
http://regexr.com/3bcrb

you can go to Community tab and search for other available email regular expressions.

or you can try this:
http://www.regular-expressions.info/email.html
Avatar of Dr. Klahn
Dr. Klahn

There's no one regular expression that can detect whether any given email is valid.  There are too many possible forms and too many possibilities.

Example 1:  Non-ASCII domain names will cause simple regular expressions to fail.  [A-Za-z0-9] is not enough to contain all the possibilities of Chinese or Middle Eastern sites.

Example 2:  It's perfectly valid for an email address to be of the form xyz@alpha.beta.gamma.delta.epsilon.somewhere.com, which "violates" the common "a@b.c.com" format.

Example 3:  There are non-standard exceptions to the general "a@b.c.com" format.  Consider exex!research!ucbvax!user@ketch-ai, a valid uucp address.

In the final analysis, the only way to know if an email address is valid is to send to that address.
Avatar of johnson1

ASKER

What would be a minimum check?
 How can I check if it contains
name (1)   - john
@ (2)  
(3)domain -   yahoo.com
and check if @ comes between the name and the domain, but not like yahoo.com@john
I use the format of 'a@b.c'.  There are no single letter user names or domain names that I know of.  I did run into one user with a 2 letter user name.  I don't use Regex though.

1. split the name at @.  If there is no @, it is not valid.
2. the first part before the '@' must be greater than 1 character.  It can contain '.'.
3. split the second part after the '@' on '.'.
4. each part of the second part must be greater than 1 character.  There are some TLDs like 'tv' that are only 2 letters.
SOLUTION
Avatar of skullnobrains
skullnobrains

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
it lacks support for stuff like "foo bar"@mydomain.com
anyway, given the fact the author has been gone for 2 months without feedback...
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Thank you very much for your help. Sorry for late reply.
If your question is answered, please assign points and close it.