I know this is been asked tons of times before , but I haven't found anything that really meets all the conditions that an email address must meet to be considered valid.
Considering the following as the structure of an email address :
[email protected]
These are all the conditions that must be met:
- An email address must not accept white spaces
- An email address must not end in a dot or a character other than a letter or a number
- Only one @ sign is allowed
- There can not be a special character before or after the at sign
- There can not be a special character before or after the domain dot (the dot after part2 of the email address)
- You can not enter two or more dots in a row in the username
- In the domain , between @ and the dot, the characters that are next to the @ and the dot must be a letter or number, in the middle the only special character allowed is the hyphen.
- The same in step 7 goes for the top-level domain(part 3 and part 4 or the email)
This is the regular expression I currently using :
^([w.-]+)@([w-]+)((.(w){2,9})+)$
But it does not meet conditions :4,5,6,7 and 8
I'm just trying to figure out how to complement my regular expression and learn in the process.
EDIT
The only special characters allowed in the email address are : dots, hyphens,underscores and the at sign
Here's a list of invalid emails
mkyong – must contains “@” symbol
[email protected] – domain can not start with dot “.”
mkyong()*@gmail.com – email’s is only allow character, digit, underscore and dash
mkyong@%*.com – email’s tld is only allow character and digit
[email protected] – double dots “.” are not allow
[email protected] – email’s last character can not end with dot “.”
mkyong@[email protected] – double “@” is not allow
[email protected] -email’s tld which has two characters can not contains digit
Valid:
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…