473,779 Members | 2,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4870
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(m yForm)
{
var emails = myForm.elements["email"].value;
var email_list = emails.split(/,\s/);
var list_len = email_list.leng th;

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

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

return true;
}

Supposing your form is something like this:

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

Aug 25 '05 #2
Christine Forber <fi*******@last name.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(stringT oTest);
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/rasterTriangleD OM.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.su fx';
(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.e lements;
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="retur n 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.tex t, te**@text.text, te**@text.text

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

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.su fx';
(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.e lements;
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="retur n 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
1934
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 local, easyphp 1.6, qui inclus apache, php et mysql. Jusque là pas de lézard. Dans une page .php, je vérifie l'existence de données et je veux signaler l'erreur en utilisant un "Window.alert" en javascript, comme
41
7126
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
2045
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 function C discovers that something is very wrong so it does an "alert" saying something like Sorry, couldn't make the necessary connection
5
6764
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
2535
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
4121
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
1276
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. Possible SQL injection and other forms of injection attacks on URLS of various server side components javascript accesses.
1
1349
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 generate several other pages using onClick events. Let's say I had a normal piece of text on the page, made to look like a link (without using the href attribute), and a user clicked on it. <a onClick="show_contact_info()">Show contact information</a>
7
3520
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 write a stand-alone form (javascript app.) to perform a site-specific keyword search. Can I do the aforementioned in Javascript? Thanks.
1
2361
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 the functions which can be used for digital signature creation/verification. For this i m referring to a vb projects(.bas )in which there are certain functions are called like SetErrorMode and LoadLibrary .. thses functions are from dll...
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10306
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6724
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.