How do I make sure all the emails is separated with slashes in html pattern? Below is what I have so far. (Regex novice here)
^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[az]+[/]{1,4}$
Currently:
abc@abc.com,abc@abc.com
false abc@abc.com/def@def.com
false abc@abc.com/aaa@aaa.com/
false abc@abc.com/
true My goals:
abc@abc.com,abc@abc.com
false abc@abc.com/def@def.com
true abc@abc.com/aaa@aaa.com/
false abc@abc.com/
false abc@abc.com
true Use a quantified group to allow any number (including 0) of emails followed by /
at the beginning, and then a single email at the end.
^(?:[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]+\/)*[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]+$
If you only want to allow 1-4 emails, change the *
to {0,3}
. This is only 0-3 because it only counts the 3 emails with /
after them, not the email at the end.
To limit the total size, you can use a lookahead at the beginning:
^(?=.{0,320}$)(?:[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]+\/)*[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]+$
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.