473,395 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

javascript code for verification of comma-delimited list of emailaddresses

I wonder if anyone knows of some javascript code to check a
comma-delimited list of email addresses for basic formating.

What I'm looking for is the javascript code to check a form field on
form submission. If there is an entry in the field, does it match the
following:

te**@text.text, te**@text.text,te**@text.text

where each address is between commas and each address is in the format
te**@text.text.

Any section of text can contain periods, hyphens, etc. There may be a
space after a comma, but it is not required.

Many thanks.

--
Christine
Aug 25 '05 #1
4 4844
Hello Christine,

Christine Forber wrote:
I wonder if anyone knows of some javascript code to check a
comma-delimited list of email addresses for basic formating.

What I'm looking for is the javascript code to check a form field on
form submission. If there is an entry in the field, does it match the
following:

te**@text.text, te**@text.text,te**@text.text

where each address is between commas and each address is in the format
te**@text.text.

Any section of text can contain periods, hyphens, etc. There may be a
space after a comma, but it is not required.

Many thanks.

--
Christine


This is javascript solution using regular expressions. It's not
completely foolproof, so you may have to do some tweaking. For
example, multiple emails must be separated by a comman and a
whitespace.

In your javascript:

function validateEmail(myForm)
{
var emails = myForm.elements["email"].value;
var email_list = emails.split(/,\s/);
var list_len = email_list.length;

re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;

for(var i = 0; i < list_len; ++i)
{
if(!re.test(email_list[i]))
{
return false;
}
}

return true;
}

Supposing your form is something like this:

<form onSubmit = "return validateEmail(this);">
<input type = "text" name = "email"/>
<input type = "submit" value = "Submit"/>
</form>

Aug 25 '05 #2
Christine Forber <fi*******@lastname.net> writes:
I wonder if anyone knows of some javascript code to check a
comma-delimited list of email addresses for basic formating.
Something like the regexp:
var re =
/^[^@\s,]+@[^@\s,]+\.[^@\s,]+(,\s?[^@\s,]+@[^@\s,]+\.[^@\s,]+)*$/;
var success = re.test(stringToTest);
If there is an entry in the field, does it match the following:

te**@text.text, te**@text.text,te**@text.text

Any section of text can contain periods, hyphens, etc.


Anything but "@", "," and whitespace in the regexp above ([^@\s,]+).

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Aug 25 '05 #3
ASM
Christine Forber wrote:
I wonder if anyone knows of some javascript code to check a
comma-delimited list of email addresses for basic formating.

What I'm looking for is the javascript code to check a form field on
form submission. If there is an entry in the field, does it match the
following:

te**@text.text, te**@text.text,te**@text.text

where each address is between commas and each address is in the format
te**@text.text.

Any section of text can contain periods, hyphens, etc. There may be a
space after a comma, but it is not required.

Many thanks.


Suppose you have a list of addresses each different of others
and one at least of this list have to be set in the form.
Suppose you did your comma-delimited list of email addresses
this way :
addr = 'te**@text.text, te**@text.text,ot***@server.sufx';
(no space after comma would be better)

function controlAddress(addressesForm) {
// array of addresses
var L = addr.split(',');
// in each address, delete space and/or '<something>' if existing
for(var i=0;i<L.length;i++) {
if(L[i].indexOf(' ')>=0) L[i]=L[i].replace(' ','');
var l = '';
if(L[i].indexOf('<')==0 && L[i].indexOf('>')>=0)
l = L[i].indexOf('>')*1+1;
if(L[i].indexOf('&lt;')==0 && L[i].indexOf('&gt;')>=0)
l = L[i].indexOf('&gt;')*1+1;
if(l!='') L[i]=L[i].substring(l);
if(L[i].indexOf('<')>0)
l = L[i].indexOf('<');
if(L[i].indexOf('&lt;')>0)
l = L[i].indexOf('&lt;');
if(l!='') L[i]=L[i].substring(0,l);
}
// control each text-box of form
var F = addressesForm.elements;
for(var i=0;i<F.length;i++){
if(F[i].type=='text') {
if(F[i].value=='') {
alert('complete this field : '+F[i].name);
F[i].focus(); F[i].select();
return false;
}
else {
var ok=false;
for(var j=0;j<L.length;j++) {
if(F[i].value==L[j]) ok=true;
}
if(!ok) {
alert('errored url in field : '+F[i].name);
F[i].focus(); F[i].select();
return false;
}
}
}
}
return true;
}
<form onsubmit="return controlAddress(this);" blah >

--
Stephane Moriaux et son [moins] vieux Mac
Aug 25 '05 #4
ASM wrote:
Christine Forber wrote:
I wonder if anyone knows of some javascript code to check a
comma-delimited list of email addresses for basic formating.

What I'm looking for is the javascript code to check a form field on
form submission. If there is an entry in the field, does it match the
following:

te**@text.text, te**@text.text,te**@text.text

where each address is between commas and each address is in the format
te**@text.text.

Any section of text can contain periods, hyphens, etc. There may be a
space after a comma, but it is not required.

Many thanks.


Suppose you have a list of addresses each different of others
and one at least of this list have to be set in the form.
Suppose you did your comma-delimited list of email addresses
this way :
addr = 'te**@text.text, te**@text.text,ot***@server.sufx';
(no space after comma would be better)

function controlAddress(addressesForm) {
// array of addresses
var L = addr.split(',');
// in each address, delete space and/or '<something>' if existing
for(var i=0;i<L.length;i++) {
if(L[i].indexOf(' ')>=0) L[i]=L[i].replace(' ','');
var l = '';
if(L[i].indexOf('<')==0 && L[i].indexOf('>')>=0)
l = L[i].indexOf('>')*1+1;
if(L[i].indexOf('&lt;')==0 && L[i].indexOf('&gt;')>=0)
l = L[i].indexOf('&gt;')*1+1;
if(l!='') L[i]=L[i].substring(l);
if(L[i].indexOf('<')>0)
l = L[i].indexOf('<');
if(L[i].indexOf('&lt;')>0)
l = L[i].indexOf('&lt;');
if(l!='') L[i]=L[i].substring(0,l);
}
// control each text-box of form
var F = addressesForm.elements;
for(var i=0;i<F.length;i++){
if(F[i].type=='text') {
if(F[i].value=='') {
alert('complete this field : '+F[i].name);
F[i].focus(); F[i].select();
return false;
}
else {
var ok=false;
for(var j=0;j<L.length;j++) {
if(F[i].value==L[j]) ok=true;
}
if(!ok) {
alert('errored url in field : '+F[i].name);
F[i].focus(); F[i].select();
return false;
}
}
}
}
return true;
}
<form onsubmit="return controlAddress(this);" blah >


Thank you to all of you who gave suggested solutions. I'll relay these
to the person who is doing the coding.

--
Christine
Aug 27 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: rcb845 | last post by:
Bonjour à tous, Je suis relativement nouveau dans ce monde. Actuellement, je construis des transactions d'administration d'une base de données avec PHP et MySql. J'ai installé sur mon poste...
41
by: Mr. x | last post by:
Hello, Can I make my java script code be invisible to other people who enter into my site by IE browser ? - How ? Thanks :)
8
by: Eric Osman | last post by:
My javascript program has reason to want to stop. For example, function A has 5 lines, the second of which calls function B, which has 5 lines, the first of which calls function C. But...
5
by: JAC | last post by:
The code JavaScript is not executed in the pages ASP in a server IIS 6.0 in Windows 2003 but if makes it in a IIS 5.1 in Windows XP, like I can configure it so that it is executed.
12
by: Duderonomoy | last post by:
Hello, I am querying the JavaScript community to learn if others are having problems with Safari and JavaScript arrays: myImages = ; then referenced like this:
5
by: VB Programmer | last post by:
I have a javascript calculator. How do I pass the value of the calculator result to another ASPX page so that I can right some VB.NET against the value? Thanks!
3
by: pantagruel | last post by:
Hi, My work is putting in a large application that is basically split up between 30 or so Javascript files. I have some security concerns about this application. Basic security concerns is: ...
1
by: Daz | last post by:
Hi. Sorry I couldn't think of a better way to word the title for this thread. My question is this: Say I have a page that is generated totally dynamically by Javascript. The code will...
7
by: bdy120602 | last post by:
In addition to the question in the subject line, if the answer is yes, is it possible to locate keywords as part of the functionality of said crawler (bot, spider)? Basically, I would like to...
1
by: sunita2006 | last post by:
Hello Team, I want to load a dll functions into script javascript for digital signature verification. I have tried this using CAPICOM dll and it woks well. I have a custom DLL which has got...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.