如果用户拼错gmail.com(如gaiml.com),如何显示错误消息 [英] How to show error message if user misspelled gmail.com(like gaiml.com)

查看:131
本文介绍了如果用户拼错gmail.com(如gaiml.com),如何显示错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户拼错gmail.com(如gaiml.com),yahoo.com在注册表单的电子邮件ID中显示错误消息,然后在asp.net中显示错误消息



提前感谢

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

推荐答案

试试这个:



使用正则表达式进行电子邮件地址验证 [ ^ ]



该链接向您展示如何检查输入是否是有效的电子邮件地址,但如果您只想使用Gmail或Yahoo,请尝试:



\ w +( [ - +。] \w +)* @(yahoo | gmail)\.com)
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)"


这是一个非常简单的正则表达式,但它会显示原理。 />
(还有很多其他的变种)



广告的问题将硬编码名称加入到表达式中是需要更新表达式以便支持新表达式。



一个更好的方法是使用有效名称的列表。此列表可以配置,以后可以轻松更改。



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.

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
    }
}


上面的解决方案是垃圾:有很多有效的域名,您可以使用正则表达式或有效域列表来检查它们。

所以看看其他人做了什么:让用户重复他的电子邮件地址,然后发送给他确认电子邮件,其中包含用于激活其帐户的自定义链接。

如果两个电子邮件地址不同,您可以向他显示错误消息。如果用户坚持两次输入相同的拼写错误,那么他将不会收到您的确认电子邮件,然后您可以在几个小时内保存删除他的帐户。
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.


这篇关于如果用户拼错gmail.com(如gaiml.com),如何显示错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆