开发者

Problem with ASP.NET Custom Validator for a Comma Separated List of Email Addresses

开发者 https://www.devze.com 2022-12-09 04:28 出处:网络
I followed a blog post here to use a custom validator to validate a list of emails. However, the Regex expression in the article:

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 opti开发者_如何学JAVAons?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消