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('<')==0 && L[i].indexOf('>')>=0)
l = L[i].indexOf('>')*1+1;
if(l!='') L[i]=L[i].substring(l);
if(L[i].indexOf('<')>0)
l = L[i].indexOf('<');
if(L[i].indexOf('<')>0)
l = L[i].indexOf('<');
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