Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 9th, 2006, 12:21 AM
Friend of Wrox
Points: 6,468, Level: 34
Points: 6,468, Level: 34 Points: 6,468, Level: 34 Points: 6,468, Level: 34
Activity: 9%
Activity: 9% Activity: 9% Activity: 9%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,835
Thanks: 12
Thanked 16 Times in 16 Posts
Send a message via AIM to mat41
Default Validate multiple email addresses...

Hello JS ers

I use this code to validate an email address:
-------------------------------------
email=document.addUser.eMail.value;
var expression=/^([a-zA-Z0-9\-\._]+)@(([a-zA-Z0-9\-_]+\.)+)([a-z]{2,3})$/;
if(!(expression.test(email)) )
{
   alert("Please enter a valid email address (50 chars max)");
   document.addUser.eMail.select();
   document.addUser.eMail.focus();
   return false;
}
-------------------------------------

It works very nicely. I would help altering it to validate several addresses. These addresses wil come in the form of a commer delimites string from an <input type="text"> form element.

Im am no JS guy. I would appreciate some assistance.

TYIA

Wind is your friend
Matt
__________________
Wind is your friend
Matt
Reply With Quote
  #2 (permalink)  
Old March 9th, 2006, 01:47 AM
Wrox Technical Editor
 
Join Date: Nov 2005
Location: , , Canada.
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try using the Javascript Split() Function, then loop through the array validating against your regular expression.

Example:

    var temp = new Array();
    temp = b.split(',');

Taken from: http://www.quirksmode.org/js/strings.html#split

- A.Kahtava
Reply With Quote
  #3 (permalink)  
Old March 9th, 2006, 08:11 PM
Friend of Wrox
Points: 6,468, Level: 34
Points: 6,468, Level: 34 Points: 6,468, Level: 34 Points: 6,468, Level: 34
Activity: 9%
Activity: 9% Activity: 9% Activity: 9%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,835
Thanks: 12
Thanked 16 Times in 16 Posts
Send a message via AIM to mat41
Default

Thanking you.

This was the logical option that first came to mind. I thought a JS guru may have a more efficient option which accounts for a commer or a semicolon address seperator, unlimited addresses being submitted etc.. (Oh, and had solved thois solution before)

TYIA

Wind is your friend
Matt
Reply With Quote
  #4 (permalink)  
Old March 15th, 2006, 10:54 PM
Friend of Wrox
Points: 6,468, Level: 34
Points: 6,468, Level: 34 Points: 6,468, Level: 34 Points: 6,468, Level: 34
Activity: 9%
Activity: 9% Activity: 9% Activity: 9%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,835
Thanks: 12
Thanked 16 Times in 16 Posts
Send a message via AIM to mat41
Default

I have been assisted with this one, the solution is:

var expression=/^(([a-zA-Z0-9\-\._]+)@(([a-zA-Z0-9\-_]+\.)+)([a-z]{2,3})([,;]\W?(?!$))?)+$/;

Adam - Thankyou I apreciate your input, this was what i was meaning by a JS Guru's method.

Wind is your friend
Matt
Reply With Quote
  #5 (permalink)  
Old March 15th, 2006, 11:00 PM
Wrox Technical Editor
 
Join Date: Nov 2005
Location: , , Canada.
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Interesting...

Thanks for the post. :)

- A.Kahtava
Reply With Quote
  #6 (permalink)  
Old March 15th, 2006, 11:17 PM
Friend of Wrox
Points: 6,468, Level: 34
Points: 6,468, Level: 34 Points: 6,468, Level: 34 Points: 6,468, Level: 34
Activity: 9%
Activity: 9% Activity: 9% Activity: 9%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,835
Thanks: 12
Thanked 16 Times in 16 Posts
Send a message via AIM to mat41
Default

Yes interesting indeed. Reg Ex is well outside my area of expertise.

FYI : This syntax works however insists the address seperator is a commer and there are no spaces between each addresss each seperator:
var expression=/^(([a-zA-Z0-9\-\._]+)@(([a-zA-Z0-9\-_]+\.)+)([a-z]{2,3})(,(?!$))?)+$/;

The version I posted as the solution in my previous post allows a semicolon or a commer and allows a space between each address and the seperator - IMO a very useful piece of code, have a nice day.



Wind is your friend
Matt
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Validate multiple email addresses mat41 Javascript 1 August 29th, 2007 12:45 AM
Multiple Bcc email addresses peterasimpson VB How-To 3 March 5th, 2006 08:53 PM
SQL query for email addresses clearsky SQL Language 1 October 7th, 2005 10:15 PM
Email Validate nskannan2007@yahoo.com Javascript How-To 3 July 3rd, 2003 11:46 PM
Email Validate nskannan2007@yahoo.com HTML Code Clinic 3 June 9th, 2003 10:49 AM



All times are GMT -4. The time now is 03:43 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.