Javascript verification email address

Source: Internet
Author: User
Tags email account

The email address has the following unifiedStandard Format: Username @ server domain name.

The user name indicates the user ID of the email address, registration name, or email recipient. The @ symbol is the domain name of the email server you are using. @ Can be read as "at", that is, ". The entire email address can be understood as the address of a user on a server on the network.
1. User Name, which can be selected by yourself. By letter ~ Z (Case Insensitive), numbers 0 ~ 9. It may consist of a dot, a minus sign, or an underscore. It can only start and end with a number or a letter, for example, beijing.2008. The username length is 4 ~ 18 characters.
2. It depends on the website you are using and represents the email service provider. For example, Netease has @ 163.com/@126.com/@188.com/@yeah.comand so on. The new wave is @ sina.com/@vip.sina.com.

 

Complete JS verification email
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)
// Number and special character Detection Function
{
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;
// "@" Detected location
VaR dot_symbol = 0;
// "." Detected location
If (char_test (Str. charat (0) = 0)
Return (1 );
// The first character must contain letters

For (I = 1; I <Str. length; I ++)
If (Str. charat (I) = '@')
{
At_symbol = I;
Break;
}
// Check the position @

If (at_symbol = Str. Length-1 | at_symbol = 0)
Return (2 );
// No email server Domain Name

If (at_symbol <3)
Return (3 );
// The account must contain less than three characters

If (at_symbol> 19)
Return (4 );
// The account contains 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 );
// Other special characters are not allowed

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)
// Check whether the server name is ".".
Return (6 );

Return (0 );
// The email name is valid.
}
Function emailcheck (STR ){
// Var ST = email_test (STR );
If (Str. Length = 0)
{Alert ("enter email ");}
Else
{
If (email_test (STR) = 1) Alert ("the first character of email must be a letter ");
If (email_test (STR) = 2) Alert ("No email server domain name ");
If (email_test (STR) = 3) Alert ("the email account contains less than three characters ");
If (email_test (STR) = 4) Alert ("the email account contains more than 19 characters ");
If (email_test (STR) = 5) Alert ("email cannot use other special characters ");
If (email_test (STR) = 6) Alert ("simply check whether there is". "To determine whether the server name is legal ");
}
}

 

<SCRIPT type = "text/JavaScript" Language = "JavaScript" src = "JS/function. js"> </SCRIPT>

Call <input name = "mail" type = "text" id = "mail" onblur = "emailcheck (this. Value)"/>

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.