Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
86
rated 0 times [  91] [ 5]  / answers: 1 / hits: 20901  / 11 Years ago, mon, october 7, 2013, 12:00:00

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 the input:



b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}b


Here's what I've tried



This doesn't seem to work for more than one:



<input type=email pattern=b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}b value= multiple>


This works, but only does the built in email validation, which seems to be something like .+@.+.



<input type=email value= multiple>


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



I have a demo here: http://codepen.io/ben336/pen/ihjKA


More From » regex

 Answers
11

Try this:



<input type=email multiple pattern=^([w+-.%]+@[w-.]+.[A-Za-z]{2,4},*[W]*)+$ value=>


Update:



Using <input type=email value= multiple> does seem to be bugged by letting a@b pass. Though I would go with this method to keep the semantics as you said, and simply use validation on the server side as well just in case someone tries to submit an email like a@b.



Just as a note, you should always validate on the server side for security reasons anyway, as client side validation can be bypassed very easily.


[#75170] Sunday, October 6, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ammonderekm

Total Points: 247
Total Questions: 105
Total Answers: 98

Location: Tuvalu
Member since Sat, Feb 11, 2023
1 Year ago
;