English 中文(简体)
如何将mail式的电子邮件清单与格雷克相匹配?
原标题:How to match a comma separated list of emails with regex?

<asp:RegularExpressionValidator, 见下文:

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

当我在上测试时,它只做罚款。

我的样本意见如下:

test@test.com,test1@test.com

我在上尝试了一项建议,但该员额却可能无法开展工作。

页: 1

最佳回答

Try this:

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

在括号之后添加<条码>+,意味着前一个群体可以出席1次或更多次。

添加<条码>><>>>>和<条码><>>>>>> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >

问题回答

登革阵将允许在 com后携带空间的电子邮件。

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

一位同事带着这个更加准确的雷切尔来进行。 以上答案似乎是通过电子邮件地址清单,其中第一个要素不是电子邮件地址。 此处还应提供经压缩后的空间。

第一种答案被选择为最贴切,如abc@xyz.comxyz@abc.com,无效。

The following regex will work for comma separate email ids aously.

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

电子邮件: Id, comma separate email 同上,但并非 com错。

First group will match string of single emailId. Second group is optionally required by * token i.e. either 0 or more number of such group but , is required to be at the beginning of such emailId which makes comma separated emailId to match to the above regex.

A simple modification of @Donut s answer allows adjacent commas, all TLDs of two characters or more, and arbitrary whitespace between email addresses and commas.

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

你们需要把白天空和空洞分割开来,但这应当是一个总体更好的用户经验。

Examples of matched lists:

  • person@example.co,chris@o.com,simon@example.capetown
  • person@example.co ,, chris@o.com, simon@example.capetown
^([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+,*[W]*)+$

这也将发挥作用。 它在电子邮件上略加严格,没有不止一个电子邮件地址,也没有一个 com。

为我工作的解决办法如下:

^([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+)(,([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+))*

以下登记局甚至将与一些最受欢迎的电子邮件合作,并支持电子邮件之间的 com。

((?:[a-zA-Z0-9!#$%& *+/=?^_`{|}~-]+(?:.[a-zA-Z0-9!#$%& *+/=?^_`{|}~-]+)*|"(?:[x01-x08x0bx0cx0e-x1fx21x23-x5bx5d-x7f]|\[x01-x09x0bx0cx0e-x7f])*")@(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?|[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-zA-Z0-9-]*[a-zA-Z0-9]:(?:[x01-x08x0bx0cx0e-x1fx21-x5ax53-x7f]|\[x01-x09x0bx0cx0e-x7f])+)]),?)+

几个例子:

Valid: planetearth@solar.com
Valid: planet.earth@solar.com
Valid: planet.earth@solar.com,blue.planet@solar.com
Valid: planet-earth@solar-system.com,/#!$%& *+-/=?^_`{}|~@solar.org,"!#$%& -/=^_`{}|~.a"@solar.org
Invalid: planet earth@solar.com

希望 这有助于。

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

<>查询<> a 各组之间的ma,但不一定在最后处理——我主要添加这一条,因为它包括一个有<代码>的冰箱(?1),因此,你只能确定一个实际的电子邮件地址,然后可以与划界商 m。

Email Address ref here: https://www.mal-expressions.info/email.html

这对我来说是联合材料和多边贸易体系的产物。

^([a-z0-9!#$%& *+/=?^_`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9])?(.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*)(([, ]+[a-z0-9!#$%& *+/=?^_`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9]).([a-z0-9]([a-z0-9-]*[a-z0-9]))*)?)*$

You can check it out here https://regex101.com/r/h0l9ks/1

下面的栏目限制性较小,更适合确认一份人工加入的 com式电子邮件地址清单。 它允许邻近的mas。

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

它将使用以下办法解决你的问题。 The following regex will take post and prespace with comma also

/^((([a-zA-Z0-9_-.]+)@([a-zA-Z0-9_-.]+).([a-zA-Zs?]{2,5}){1,25})(s?,s*?))$/

我知道,我很晚了一点,但我的数字是我增加两个百分点,因为接受的回答是,在没有礼让的情况下,相互配对电子邮件地址。

我提议的是:

^[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,}([A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,})*

它类似于接受的答复,但解决了我所谈论的问题。 我提出的解决办法不是一次或多次寻找“电子邮件地址,然后是任择礼让”,即所接受的回答,而是这一对“电子邮件地址的查询,随后是选择性的定制电子邮件地址。

这使问题得以解决,将 com和随后的电子邮件地址分类,使整个群体成为一种选择,而不仅仅是 com。

Notes: This regex is meant to be used with the insensitive flag enabled.
You can use whichever regex to match an email address you please, I just used the one that I was already using. You would just replace each [A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,} with whichever regex you want to use.

最容易的解决办法如下。 这将与模拟清单相匹配。 在您的法典中使用以下规范。

Regex: [^,]+?

^([w+-.%]+@[w-.]+.[A-Za-z]+)(, ?[w+-.%]+@[w-.]+.[A-Za-z]+)*$

每一 com后0或1个空间的工程,以及长期推广工程

除我们在每份电子邮件地址之后添加 com外,I区法院对这个问题的处理十分有利。

^((s*?)[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+.[a-zA-Z,]{2,4}(s*?),)*

这样做的理由如下:

  1. (s*?) will allow spaces at the start.
  2. [a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+.[a-zA-Z,]{2,4} is common email pattern.
  3. (s*?) will allow space at the end too.
  4. , will restrict comma.

对我来说,这封信完全用于多个电子邮件:

^(w+((-w+)|(.w+))*@[A-Za-z0-9]+((.|-)[A-Za-z0-9]+)*.[A-Za-z0-9]{2,4}s*?,?s*?)+$
RegEx Component Explanation
^ Matches the start of the string.
w+ Matches one or more word characters (letters, digits or underscores).
((-w+)|(.w+))* Matches zero or more occurrences of a hyphen followed by one or more word characters or a period followed by one or more word characters.
@ Matches the @ symbol.
[A-Za-z0-9]+ Matches one or more letters or digits.
((.|-)[A-Za-z0-9]+)* Matches zero or more occurrences of a period or hyphen followed by one or more letters or digits.
.[A-Za-z0-9]{2,4} Matches a period followed by two to four letters or digits.
s*?,?s*? Matches optional whitespace followed by an optional comma followed by optional whitespace.
+ Matches one or more occurrences of the entire expression.
$ Matches the end of the string.

最新版本@Laxmi Prasad

^([^s@,]+@[w.-]+.[A-Za-z]{2,63})(,[^s@,]+@[w.-]+.[A-Za-z]{2,63})*$

这试图涵盖最大匹配的电子邮件,但在需要排除某些特殊性质时,可按例加以改进。 避免连续的 com,支持最长的限期长度(63)。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!