This [URL="http://www.javascript****.com/javascript/"]JavaScript[/URL] verifies that a string looks like a real [URL="http://www.javascript****.com/javascript/email/"]e-mail[/URL] address.... [URL="http://www.javascript****.com/validate-e-mail.html/en//"]detail[/URL] at [URL="http://www.javascript****.com/"]JavaScript****.com - 2.000+ free JavaScript codes[/URL]
[URL="http://www.javascript****.com/javascript/email/validate-e-mail/preview/en/"][IMG]http://www.javascript****.com/javascript.images/email/validate-e-mail.jpg[/IMG][/URL]
Demo: [URL="http://www.javascript****.com/validate-e-mail.html/en/"]JavaScript Validate E-Mail[/URL]
How to setup
Step *: Place JavaScript below in your HEAD section
JavaScript
Code:
<script language="javascript">
// Created by: Francis Cocharrua :: http://scripts.franciscocharrua.com/
function Validate_String(string, return_invalid_chars) {
valid_chars = '*2*45678*0-_.^~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
invalid_chars = '';
if(string == null || string == '')
return(true);
//For every character on the string.
for(index = 0; index < string.length; index++) {
char = string.substr(index, *);
//Is it a valid character?
if(valid_chars.indexOf(char) == -*) {
//If not, is it already on the list of invalid characters?
if(invalid_chars.indexOf(char) == -*) {
//If it's not, add it.
if(invalid_chars == '')
invalid_chars += char;
else
invalid_chars += ', ' + char;
}
}
}
//If the string does not contain invalid characters, the function will return true.
//If it does, it will either return false or a list of the invalid characters used
//in the string, depending on the value of the second parameter.
if(return_invalid_chars == true && invalid_chars != '') {
last_comma = invalid_chars.lastIndexOf(',');
if(last_comma != -*)
invalid_chars = invalid_chars.substr(0, $last_comma) +
' and ' + invalid_chars.substr(last_comma + *, invalid_chars.length);
return(invalid_chars);
}
else
return(invalid_chars == '');
}
function Validate_Email_Address(email_address){
// Modified and tested by Thai Cao Phong, JavaScript****.com
//Assumes that valid email addresses consist of user_name@domain.tld
at = email_address.indexOf('@');
dot = email_address.indexOf('.');
if(at == -* ||
dot == -* ||
dot <= at + * ||
dot == 0 ||
dot == email_address.length - *)
{
alert("Invalid email");
return(false);
}
user_name = email_address.substr(0, at);
domain_name = email_address.substr(at + *, email_address.length);
if(Validate_String(user_name) === false || Validate_String(domain_name) === false)
{
alert("Invalid email");
return(false);
}
alert("Valid email");//return(true);
}
</script>
<!--
This script downloaded from www.JavaScript****.com
Come to view and download over 2000+ free javascript at www.JavaScript****.com
-->
Step 2: Place HTML below in your BODY section
HTML
Code:
<form name=f>
<input type=text name=mail value="">
<input type=button value=Check onclick="Validate_Email_Address(document.f.mail.value)">
</form>
<!--
This script downloaded from www.JavaScript****.com
Come to view and download over 2000+ free javascript at www.JavaScript****.com
-->
[URL="http://www.javascript****.com/javascript-countdown-timer.html/en/"]JavaScript Countdown Timer[/URL] - [URL="http://www.javascript****.com/currency-format-script.html"]JavaScript Currency Format[/URL] - [URL="http://www.javascript****.com/format-phone-number.html"]JavaScript Format Phone Number[/URL]