»
EnglishFrenchVietnamese

Print - Email Validator - JavaScriptBank.com

Full version: jsB@nk » Email » Email Validator
URL: https://www.javascriptbank.com/email-validator.html

Email Validator © JavaScriptBank.comUse this JavaScript to validate Email addresses on the client-side. To validate an Email address, use the function in the following manner: isEmail(someEmailAddress). The function returns true if the Email is valid, else the function returns false.

Full version: jsB@nk » Email » Email Validator
URL: https://www.javascriptbank.com/email-validator.html



CSS
<style type="text/css">td{font-family:verdana,arial,helvetica; font-size:10pt}.ip{width:220px; height:20px; border:#000000 solid 1px}.btn{height:20px; background:#000000; border:0px; font-family:verdana,arial,helvetica; color:#FFFFFF; font-weight:bold; cursor:hand}code{font-weight:bold}a{color:#000000}a:hover{color:#666666}</style><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


JavaScript
<script language="JavaScript">////////////////////////////////////////////////////<Email Validator>//// (c) 2003 Premshree Pillai////Written on: 29/04/03 (dd/mm/yy)////http://www.qiksearch.com////http://premshree.resource-locator.com////Email : [email protected]/////////////////////////////////////////////////////* Without RegExps */function isEmail(who) {function isEmpty(who) {var testArr=who.split("");if(testArr.length==0)return true;var toggle=0;for(var i=0; i<testArr.length; i++) {if(testArr[i]==" ") {toggle=1;break;}}if(toggle)return true;return false;}function isValid(who) {var invalidChars=new Array("~","!","@","#","$","%","^","&","*","(",")","+","=","[","]",":",";",",","\"","'","|","{","}","\\","/","<",">","?");var testArr=who.split("");for(var i=0; i<testArr.length; i++) {for(var j=0; j<invalidChars.length; j++) {if(testArr[i]==invalidChars[j]) {return false;}}}return true;}function isfl(who) {var invalidChars=new Array("-","_",".");var testArr=who.split("");which=0;for(var i=0; i<2; i++) {for(var j=0; j<invalidChars.length; j++) {if(testArr[which]==invalidChars[j]) {return false;}}which=testArr.length-1;}return true;}function isDomain(who) {var invalidChars=new Array("-","_",".");var testArr=who.split("");if(testArr.length<2||testArr.length>4) {return false;}for(var i=0; i<testArr.length; i++) {for(var j=0; j<invalidChars.length; j++) {if(testArr[i]==invalidChars[j]) {return false;}}}return true;}var testArr=who.split("@");if(testArr.length<=1||testArr.length>2) {return false;}else {if(isValid(testArr[0])&&isfl(testArr[0])&&isValid(testArr[1])) {if(!isEmpty(testArr[testArr.length-1])&&!isEmpty(testArr[0])) {var testArr2=testArr[testArr.length-1].split(".");if(testArr2.length>=2) {var toggle=1;for(var i=0; i<testArr2.length; i++) {if(isEmpty(testArr2[i])||!isfl(testArr2[i])) {toggle=0;break;}}if(toggle&&isDomain(testArr2[testArr2.length-1]))return true;return false;}return false;}}}}/* With RegExp */function isEmail2(who) {var email=/^[A-Za-z0-9][\w-.]+@[A-Za-z0-9]([\w-.]+[A-Za-z0-9]\.)+([A-Za-z]){2,4}$/i;return(email.test(who));}</script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<table width="450" align="center"><tr><td><form name="form1"><input type="text" name="email" class="ip" value="Enter Email"> <input type="button" value="isEmail()" class="btn" onClick="if(isEmail(document.form1.email.value)){alert('Valid Email!');}else{alert('Invalid Email!');}"><input type="button" value="isEmail2()" class="btn" onClick="if(isEmail2(document.form1.email.value)){alert('Valid Email!');}else{alert('Invalid Email!');}"></form> To validate an Email address, use the function in the following manner: <code>isEmail(someEmailAddress)</code>. The function returns <code>true</code> if the Email is valid, else the function returns <code>false</code>.<br><br>The <code>isEmail()</code> function does not use regular expressions while the <code>isEmail2()</code> function uses regular expression for validation.<hr noshade />© 2003 <a href="http://premshree.resource-locator.com">Premshree Pillai</a>.</td></tr></table><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->