How to match a comma separated list of emails with regex?

前端 未结 13 1313
一整个雨季
一整个雨季 2020-12-15 07:29

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



        
13条回答
  •  [愿得一人]
    2020-12-15 07:59

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

    The point about requiring a comma between groups, but not necessarily at the end is handled here - I'm mostly adding this as it includes a nice subgroup with the (?1) so you only define the actual email address regex once, and then can muck about with delimiters.

    Email address ref here: https://www.regular-expressions.info/email.html

提交回复
热议问题