<xx***********@ tampascanner.in fo> wrote in message news:gq******** *************** *********@4ax.c om...
I am looking to do some email validation and many of the scripts I've located
online are great basic email validators.
They check to see that the email address is something along the lines of
somethin@a_vali d_host.at_a_valid_tld
Thats great, looking for that, BUT
I then want to EXCLUDE certain domains, ie: webmail hosts, or what ever hosts I
add to a list.
I want to work this with my basic update form which gets sent via the a CGI
script form mail item
User fills out form
clicks submit
JS checks to see if its a valid email address AND NOT a webmail or other
excluded hosts address. If so then submits via my normal formmail.pl script.
Any one already invented this?
No, but I've made a simple addition to an existing script. It tests the basic address format without searching
for illegal characters, giving a descriptive message of any error. Then it checks for unwanted domains with
any suffix: .fr or co.uk etc, so just add basic names to the list. It picks-up .....@mail.unWa nted.etc. It
will not pick-up
ya********@anAc ceptedHost.etc or
xx*@hotmailHate rs.etc
Having said that, I expect that most typos are undetectable in that they don't break the basic format. Also,
you cannot expect realistically to detect all webmail hosts, and it may not be too tactful to tell a user that
you're not enamoured of his/her email address.
<script type='text/javascript'>
function emTest(emString , showMessage)
{ // S Chalmers 2005
var badHosts=["usa","msn","ho tmail","yahoo", "pointedEar s"];
var emaData=
/\,/, false, "Comma (,) found",
/\s/, false, "Spaces not allowed",
/@/, true, "No @ sign",
/@.*@/, false, "More than one @",
/^@/, false, "Nothing preceding @",
/\.@/, false, "@ preceded by '.'",
/@\./, false, "@ followed by '.'",
/@.+\./, true, "No '.' anywhere after @",
/\.\./, false, "=>..",
/^\./, false, "Cannot start with '.'",
/\.$/, false, "Cannot end with '.'",
/.+\.[a-z]{2,}$/i, true, "Must end with 2 or more letters"
];
var ok=true, dl=emaData.leng th, hl=badHosts.len gth;
emString=emStri ng.replace(/^\s+|\s+$/g,'');
for(var i=0; i<dl && ( emaData[i].test( emString ) ^ !emaData[i+1] ); i+=3)
;
if(i!=dl)
{
ok=false;
if(showMessage)
alert("Error in format of e-mail address:\n\n" + emString + "\n\n" + emaData[i+2]);
}
else
{
for(var j=0; j<badHosts.leng th && !new RegExp("[@.]"+badHosts[j]+"\\.","i").tes t(emString); j++)
;
if(j!=hl)
{
ok=false
if(showMessage)
alert("Excluded mail host [ "+badHosts[j]+" ]");
}
}
return ok;
}
</script>
<FORM onsubmit="retur n false">
<input size="50" type="text" name='ema'><BR>
<input type="button" onclick="emTest (this.form.ema. value, true)" value='TEST'>
</FORM>
--
Stephen Chalmers
http://makeashorterlink.com/?H3E82245A
547265617375726 520627572696564 206174204F2E532 E207265663A2054 51323437393134