简体   繁体   English

用逗号分隔的多封电子邮件的正则表达式和有效的电子邮件

[英]Regex for multiple emails separated by commas with valid emails

I have regex to check multiple valid emails separated by commas, But I'm not able to update it to allow multiple trailing and leading whitespace.我有正则表达式来检查用逗号分隔的多个有效电子邮件,但我无法更新它以允许多个尾随和前导空格。 I should allow below pattern to match my regex.我应该允许以下模式匹配我的正则表达式。

abc@test.com,bcd@test.com, new@test.com,   hello@test.com   ,new@test.com // allow
abc@test.com bcd@test.comnew@test.com// don't allow

Regex which I've now.我现在拥有的正则表达式。

^(\s?[^\s,]+@[^\s,]+\.[^\s,]+\s?,)*(\s?[^\s,]+@[^\s,]+\.[^\s,]+)$

The above regex is not allowing the pattern上面的正则表达式不允许该模式

abc@test.com,bcd@test.com, new@test.com,   hello@test.com   ,new@test.com

It allows only one white space before an after the comma.它在逗号之后只允许一个空格。 I want the regex to allow multiple white space before and after the comma我希望正则表达式在逗号前后允许多个空格

Why not first spiting the string:为什么不先吐出字符串:

function getValidEmailAddresses(strInput)
{
return strInput.split(',').map(p => p.trim())
               .filter(c=> c.test(/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/));

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM