Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

validate multiple email addresses in a textarea

 
Pravin Jain
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I validate multiple email addresses entered in a textarea.
one per line in the text area.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64623
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On the client or server? Do you know how you would validate a single such entry? What code have you written so far?
 
Pravin Jain
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
On the client or server? Do you know how you would validate a single such entry? What code have you written so far?


The validation is required on the client side using javascript.
I have a form with several input fields. one of the fields is
for accepting multiple email addresses, one email per line. I
need to check that each line contains a valid email address.
The field may be left blank, but if there is any entry then it
should be a valid email address.

I have got a regex pattern which can validate a single entry.
The regex is as follows:
/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i

will it work if I simply group this regex as follows:
(/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i)*



Thanks
Pravin
[ October 02, 2007: Message edited by: Pravin Jain ]
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I prefer to create several HTML input fields, so each one can be validated and normalized independently.
 
Paul Clapham
Sheriff
Pie
Posts: 20750
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or better still, don't validate e-mail addresses at all.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
will it work if I simply group this regex as follows:
(/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i)*


Nope, the ()* must be within the regular expression, i.e. within the /.../

Try this
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic