Javacript verification function

Source: Internet
Author: User
In ASP, ASP. NET input verification to use some common verification, such as name, E-MAIL, phone number, etc., I keep the commonly used records, so as not to look up inconvenient.

// Check whether it is composed of digits
Function isdigit (s)
{
VaR patrn =/^ [0-9] {1, 20} $ /;
If (! Patrn.exe C (s) return false
Return true
}
// Check Logon Name: You can enter only 5-20 strings starting with a letter, which can contain numbers, "_", and ".".
Function isregisterusername (s)
{
VaR patrn =/^ [A-Za-Z] {1} ([a-zA-Z0-9] | [. _]) {} $ /;
If (! Patrn.exe C (s) return false
Return true
}

// Password verification: only 6-20 letters, numbers, and underscores can be entered
Function ispasswd (s)
{
VaR patrn =/^ (\ W) {6, 20} $ /;
If (! Patrn.exe C (s) return false
Return true
}

// Verify the mobile phone number. It must start with a number and can contain "-" in addition to a number.
Function ismobil (s)
{
VaR patrn =/^ ([0-9] {11,13 })? $ /;
If (! Patrn.exe C (s) return false
Return true
}

Function isemail (SRC ){
Return (isemail1.test (SRC) & isemail2.test (SRC ));
}

Isemail1 =/^ \ W + ([\. \-] \ W +) * \ @ \ W + ([\. \-] \ W + )*\. \ W + $ /;
Isemail2 =
/^. * @ [^ _] * $/;

Function onlychinese ()
{
If (window. event. keycode> = 32) & (window. event. keycode <= 126 ))
{
Window. event. keycode = 0;
}
}

I have tried a lot of functions that can only input Chinese characters for online verification. I think this is very useful. If it is not a Chinese character in the text box, it cannot be entered. If it is just a name, you have to limit the number of words, filter out special characters.
Eg:
ASP usage:
<Input name = "usernamecn" type = "text"Onkeypress="Onlychinese(); ">
 
Today, you can see the verified Chinese characters.
1. Determine whether the string is a consecutive Chinese character (excluding English and any other symbols and numbers ):
RegEx. ismatch ("Chinese", "^ [\ u4e00-\ u9fa5] + $ ");
2. Determine whether the string is a Chinese character string (only English characters are excluded but other symbols and numbers are allowed ):
! RegEx. ismatch ("Chinese", @ "[A-Za-Z]");
This is very common.

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.