aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes validate multiple email addresses in a textarea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "validate multiple email addresses in a textarea" Watch "validate multiple email addresses in a textarea" New topic
Author

validate multiple email addresses in a textarea

Pravin Jain
Ranch Hand

Joined: May 20, 2007
Posts: 60
How do I validate multiple email addresses entered in a textarea.
one per line in the text area.


The Zen of Java Programming.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

On the client or server? Do you know how you would validate a single such entry? What code have you written so far?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Pravin Jain
Ranch Hand

Joined: May 20, 2007
Posts: 60
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

Joined: Jul 09, 2001
Posts: 1180
I prefer to create several HTML input fields, so each one can be validated and normalized independently.


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

Or better still, don't validate e-mail addresses at all.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
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


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: validate multiple email addresses in a textarea