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.