Verify that the email address is a valid and complete instance

Source: Internet
Author: User
1. Index.html


<title>email address is legal index.html</title>
<script language = "JavaScript" src= "Mail.js" ></script>
<script language= "JavaScript" >
<!--
function Mail_process (stringin)
{
var num=email_test (Stringin);
var str= "";
if (num!=0)
{
Switch (NUM)
{
Case 1:
Str= "First character must use Letter!" or cannot be empty! Please return to refill. ";
Break
Case 2:
Str= "You forgot to fill out the address of the mail server!" Please return to refill. ";
Break
Case 3:
Str= "Your account number is too short to be less than three characters!" please return the refill. ";
Break
Case 4:
Str= "Your account number is too long to be more than 19 characters!" Please return the refill. ";
Break
Case 5:
Str= "You have used illegal characters!" Please return the refill. ";
Break
Case 6:
Str= "Your mail server's address is illegal!" please return to refill. ";
Break
Default
Str= "Your email address is illegal! Please return to refill. ";
}
alert (str);

}
Else
{
Alert ("Thank you!");
Eval (Window.close ());
}

}
-->
</script>

<body>
<form method= "POST" >
<p> Please enter your e-mail address:
<input type= "text" name= "Email_add" size= ">"
<input type= "Submit" value= "OK" name= "B1" ></p>
</form>
</body>



2.//mail.js
function Char_test (CHR)
Character detection function
{
var i;
var smallch= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var bigch= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (i=0;i<26;i++)
if (Chr==smallch.charat (i) | | Chr==bigch.charat (i))
return (1);
return (0);
}

function Spchar_test (CHR)
Digital and special character detection functions
{
var i;
var spch= "_-.0123456789";
for (i=0;i<13;i++)
if (Chr==spch.charat (i))
return (1);
return (0);
}

function Email_test (str)
{
var i,flag=0;
var at_symbol=0;
Location of "@" detected
var dot_symbol=0;
“.” Location of the test
if (Char_test (Str.charat (0)) ==0)
return (1);
First character must be in letter

for (i=1;i<str.length;i++)
if (Str.charat (i) = = ' @ ')
{
At_symbol=i;
Break
}
Detect the location of "@"

if (at_symbol==str.length-1 | | at_symbol==0)
return (2);
No mail server domain name

if (at_symbol<3)
return (3);
Account number is less than three characters

if (at_symbol>19)
return (4);
Account number is more than 19 characters

for (i=1;i<at_symbol;i++)
if (Char_test (Str.charat (i)) ==0 && spchar_test (Str.charat (i)) ==0)
return (5);
for (i=at_symbol+1;i<str.length;i++)
if (Char_test (Str.charat (i)) ==0 && spchar_test (Str.charat (i)) ==0)
return (5);
Cannot use other special characters

for (i=at_symbol+1;i<str.length;i++)
if (Str.charat (i) = = '. ') dot_symbol=i;
for (i=at_symbol+1;i<str.length;i++)
if (dot_symbol==0 | | dot_symbol==str.length-1)
Simple detection has no "." To determine whether the server name is legitimate
return (6);

return (0);
Mail name Legal
}
Summary of!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.