使用ASP.NET自定义验证问题的电子邮件地址的逗号分隔的列表 [英] Problem with ASP.NET Custom Validator for a Comma Separated List of Email Addresses

查看:183
本文介绍了使用ASP.NET自定义验证问题的电子邮件地址的逗号分隔的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我也跟着博客张贴在这里使用自定义的验证器来验证电子邮件的列表。然而,正则表达式EX pression文章:

 正则表达式emailRegEx =新的正则表达式(@\ w +([ -  +'] \ W +)* @ \ w +([ - ] \ W +)* \ \ W +(。 [ - ] \ W +)*,
                       RegexOptions.IgnoreCase);
 

通过允许此电子邮件地址:

 APL@domain.com 123@domain.com
 

这显然是无效的。

我怎样才能将其更改为标志,这​​是无效的?

请注意:当您使用的核心正则表达式验证器使用相同的正则表达式EX pression它确实赶上了电子邮件,所以也许它是与匹配的选项的问题

感谢

解决方案

 正则表达式emailRegEx =新的正则表达式(@^ \ w +([ -  +'] \ W +)* @ \ W +([ - ] \ W +)* \ \ W +([ - ] \ W +)* $,RegexOptions.IgnoreCase)。
 

看起来你需要终止定期EX pression。检查'^'处开始和$以前pression上面的端

I followed a blog post here to use a custom validator to validate a list of emails. However, the Regex expression in the article:

Regex emailRegEx = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*",
                       RegexOptions.IgnoreCase);

allows this email address through:

"APL@domain.com 123@domain.com"

which is clearly invalid.

How can I change it to flag this as invalid?

Note: When you use the core RegEx Validator with the SAME regex expression it DOES catch that email, so perhaps it is a problem with the matching options?

Thanks

解决方案

Regex emailRegEx = new Regex(@"^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$", RegexOptions.IgnoreCase);

It looks like you need to terminate your regular expression. Check the '^' at the start and the "$" at the end of the expression above.

这篇关于使用ASP.NET自定义验证问题的电子邮件地址的逗号分隔的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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