»
AnglaisFranaisVietnamien

Imprimer - E-mail de validation - JavaScriptBank.com

Version complte: jsB@nk » Email » E-mail de validation
URL: http://www.javascriptbank.com/e-mail-validation.html

E-mail de validation © JavaScriptBank.comCet JavaScript utilise des expressions régulières pour vérifier qu'une chaîne contient un appel valide e-mail adresse. Notez qu'il ne sera pas capturer tous les e-mails non valides, comme la plupart des scripts. Toutefois, pour les plus fins et intentions, ce JavaScript devrait servir de son objet même, par le rejet commun e-mail les fautes de frappe, tout en laissant place à l'obscure encore valide e-mails à passer.

Version complte: jsB@nk » Email » E-mail de validation
URL: http://www.javascriptbank.com/e-mail-validation.html



JavaScript
<script language=javascript>function validateTOMailID()//Validate TO, CC and BCC Mail-IDs{var flag = true;if(document.form.toEMailID.value != "")//Validate TO Mail-ID{flag = validEMailIDs(document.form.toEMailID.value);}return flag;}function validEMailIDs(mailIDs)//Validate E-Mail-IDs{var valid = true;if(mailIDs.indexOf(";") != -1)//Check wheter Mail-IDs are separated by semicolons{alert("Mail-IDs should be separated by commas.");valid = false;}else{var arrMailID = mailIDs.split(",");//split all Mail-IDs based on comma - Array of Mail-IDsfor(var j=0; j<arrMailID.length; j++)//check for each Mail-ID{// 1+@3+ [or x@x.x] is as close as we will testvar mailID = arrMailID[j];        var mailID = trim(mailID);//Trim Each Mail-IDif(mailID == ""){valid = false;alert("Please remove the un-necessary comma operator(s).");break;}var dot = mailID.lastIndexOf(".");//index of dot symbolvar at = mailID.indexOf("@");//index of at symbolvar dom = dot - at;var space = mailID.indexOf(" ");//index of space charactervar lenMailID=mailID.length;if( (lenMailID < 5) || (space != -1) || (at == -1) || (dot == -1) || (at < 1) || ( dom < 2) ||   (dot == lenMailID-1) || (at == lenMailID-1) ){valid = false;alert("The format of Mail-ID \"" + mailID + "\" is not correct.");break;}}}return valid;}function trim(str){return str.replace( /^\s+/g,'').replace(/\s+$/g,'');}</script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<script language=javascript>document.write( 'FirstName.LastName@Site.Section.com is a ' + validEMailIDs('FirstName.LastName@Site.Section.com') + ' email<br />' );document.write( 'FullName@Site.com is a ' + validEMailIDs('FullName@Site.com') + ' email<br />' );</script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->