如何匹配一个逗号分隔与正则表达式的电子邮件列表? [英] How to match a comma separated list of emails with regex?

查看:399
本文介绍了如何匹配一个逗号分隔与正则表达式的电子邮件列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图验证的逗号分隔的电子邮件列表在文本框中使用 ASP:RegularEx pressionValidator ,见下图:

Trying to validate a comma-separated email list in the textbox with asp:RegularExpressionValidator, see below:

<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
                    runat="server" ErrorMessage="Wrong email format (separate multiple email by comma [,])" ControlToValidate="txtEscalationEmail"
                    Display="Dynamic" ValidationExpression="([\w+-.%]+@[\w-.]+\.[A-Za-z]{2,4},?)" ValidationGroup="vgEscalation"></asp:RegularExpressionValidator>

它工作得很好,当我测试它在 http://regexhero.net/tester/ ,但它不工作在我的网页。

It works just fine when I test it at http://regexhero.net/tester/, but it doesn't work on my page.

下面是我的样本输入:

test@test.com,test1@test.com

我试过在<一个建议href=\"http://stackoverflow.com/questions/1598349/problem-with-asp-net-custom-validator-for-a-comma-separated-list-of-email-address\">this帖子,但不能得到它的工作。

I've tried a suggestion in this post, but couldn't get it to work.

P.S。我不希望在适当的电子邮件验证的讨论

p.s. I don't want a discussion on proper email validation

推荐答案

试试这个:

^([\w+-.%]+@[\w-.]+\.[A-Za-z]{2,4},?)+$

添加 + 括号装置之后,该preceding基团可以是present 1次或多次。

Adding the + after the parentheses means that the preceding group can be present 1 or more times.

添加 ^ $ 表示字符串的开始,比赛开始之间的任何东西(或匹配和字符串的末尾)的端部导致验证失败。

Adding the ^ and $ means that anything between the start of the string and the start of the match (or the end of the match and the end of the string) causes the validation to fail.

这篇关于如何匹配一个逗号分隔与正则表达式的电子邮件列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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