Click here to Skip to main content
15,885,630 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How to show error message if user misspelled gmail.com(like gaiml.com),yahoo.com in email id of registration form then show error message in asp.net

thanks in advance
Posted
Comments
syed shanu 2-Jul-14 4:05am    
Hi,
Check this link hope this will help you.

http://forums.asp.net/t/1860389.aspx?validation+expression+for+gmail+yahoo

you can use regular expression for this

Try this :

Email Address Validation Using Regular Expression[^]

That link show you how to check if input is an valid Email Address, but if you just wanna use Gmail or Yahoo, try this :

"\w+([-+.]\w+)*@(yahoo|gmail)\.com)"
 
Share this answer
 
This is a very simple regular expression, but it will show the principle.
(There are plenty of other variants out there)

The problem with adding hard coded names into the expression is that you need to update the expression in order support a new one.

A maybe better way is to have a list with valid names. This list can be configurable and easy to change later on.

C#
Regex MailExpression = new Regex(@"(?<name>\S+)@(?<provider>\S+)\.(?<code>\S+)");
// Hard coded here, but should be read from config file
List<string> validProviderNames = new List<string> {"yahoo", "gmail", "whatever" };

string testAddress = "harry.hacker@yahaa.com";
Match m = MailExpression.Match(testAddress);
if (m.Success)
{
    string providerName = m.Groups["provider"].Value;
    if (!validProviderNames.Contains(providerName.ToLower()))
    {
        throw new Exception(String.Format("The provider name '{0}' is not valid.", providerName));
    }
    else
    {
        // Do som stuff
    }
}
 
Share this answer
 
The solutions above are crap: there are far to many valid domains that you could check them with a regular expression or a list of "valid" domains.
So look what others do: have the user repeat his email address, then send him a confirmation email with a custom link for activating his account.
If the two email addresses differ, you can show him an error message. If the user "insists" on typing the same typo twice, well, he won't receive your confirmation email, and then you can savely delete his account within a few hours.
 
Share this answer
 
Comments
George Jonsson 3-Jul-14 21:16pm    
It is always nice with a besserwisser.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900