使用ASP.NET自定义验证问题的电子邮件地址的逗号分隔的列表逗号、自定义、电子邮件地址、问题

2023-09-05 02:37:56 作者:如今哥很缺爱

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

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

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

 APL@domain.com 123@domain.com
 

这显然是无效的。

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

Apple Id 的验证电子邮件为什么收不到

请注意:当您使用的核心正则表达式验证器使用相同的正则表达式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.