In my application I am usinfg an email validation. I am using this for email verification. It checks only for the entered text is in a normal email format. When I am entering an email like example@example.comfg
then it return true. How can I check this type of error in email.
Asked
Active
Viewed 1,236 times
0

Nelson T Joseph
- 2,683
- 8
- 39
- 56
-
As you say it validates format only; to do otherwise you would need to check against a list of every valid top level domain. If you want to check it *exists* do something like http://stackoverflow.com/questions/1778390/check-if-email-are-valid-and-exists?rq=1 – Alex K. Sep 20 '12 at 10:38
-
Maybe get the index of "." and then deduce whether the part after it '= com' or not? – user959631 Sep 20 '12 at 10:38
-
Sorry, i do not quite understand the error in the above example. If it is about the TLD not being com i think that you would have to check against a maintained list of TLD. Also, what do you mean by "how can i check this type of error". Isn't the regex-based validator appropriate? – Gros Lalo Sep 20 '12 at 10:39
-
I think that the OP wants to reject the `.comfg` extension as a non-valid TLD... In this case you can either use a lookup table or enforce the last chunk of the address to be only 2 or 3 chars long that would suffice in many cases. – Yannick Blondeau Sep 20 '12 at 10:45
1 Answers
2
If the problem is that you think that comfg
is wrong and it should be 3 characters max like in com
, the simply change the Regex like that:
Regex.IsMatch(strIn,
@"^(?("")(""[^""]+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))" +
@"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,3}))$");

Gros Lalo
- 1,078
- 7
- 20
-
But abc@company.info is a valid email. In this case "abc@company.info" also be considered as an invalid email. – Nelson T Joseph Sep 20 '12 at 10:54
-
Right on. This is why i am wondering why you thought comfg was wrong. If you think it is a question of length then you can adjust that with the last digit in the above regex. But, if the meaning of that last part is more than just length then you need to filter against a known list. So, the question you should ask yourself is will you allow .aaaa or, .mnxy as well as .info. My advice would be to use the Regex provided by link in your question. You can validate the structure of the email address but not its existence until you try to access it. – Gros Lalo Sep 20 '12 at 11:15