Validate Multiple Email Addresses with HTML5

前端 未结 3 1169
你的背包
你的背包 2021-02-15 14:06

I\'m trying to construct an email form that takes multiple comma separated emails as an input and verifies them using HTML5. I want to use the following regex to sanity check t

3条回答
  •  礼貌的吻别
    2021-02-15 14:16

    Is there a way to mix pattern and multiple so the regex checks each item in the comma separated list?

    Yes. If the regex to match an element is foo, then

    ^(?:foo(?:,(?!$)|$))*$
    

    will match a comma separated list of foos.

    The separator is (?:,(?!$)|$) which will match either a required comma that does not end the input, or the end of input.

    That separator is horribly ugly, but allows you to avoid duplicating the "foo" as long as no suffix of the separator is a required non-empty prefix of the body.

提交回复
热议问题