JS Regular Expression // check whether all numbers are composed of function isDigit (s) {var patrn =/^ [0-9] {} $/; if (! Patrn.exe c (s) return false return true} // check the logon name. You can enter only 5-20 names starting with a letter, including numbers, "_", and ". "string Java code function isRegisterUserName (s) {var patrn =/^ [a-zA-Z] {1} ([a-zA-Z0-9] | [. _]) {4, 19} $/; if (! Patrn.exe c (s) return false return true} // verify the User name: only 1-30 strings starting with letters can be entered. Java code function isTrueName (s) {var patrn =/^ [a-zA-Z] {1, 30} $/; if (! Patrn.exe c (s) return false return true }}// check password: only 6-20 letters, numbers, and underscores can be entered
Copy codeThe Code is as follows:
Function isPasswd (s)
{
Var patrn =/^ (\ w) {6, 20} $ /;
If (! Patrn.exe c (s) return false
Return true
}
// Verify the phone number and fax number. The phone number can start with "+" and contain "-" in addition to numbers.
Copy codeThe Code is as follows:
Function isTel (s)
{
// Var patrn =/^ [+] {0, 1} (\ d) {1, 3} []? ([-]? (\ D) {1, 12}) + $ /;
Var patrn =/^ [+] {0, 1} (\ d) {1, 3} []? ([-]? (\ D) | []) {1, 12}) + $ /;
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.
Copy codeThe Code is as follows:
Function isMobil (s)
{
Var patrn =/^ [+] {0, 1} (\ d) {1, 3} []? ([-]? (\ D) | []) {1, 12}) + $ /;
If (! Patrn.exe c (s) return false
Return true
}
// Verify the zip code
Copy codeThe Code is as follows:
Function isMobil (s)
{
Var patrn =/^ [+] {0, 1} (\ d) {1, 3} []? ([-]? (\ D) | []) {1, 12}) + $ /;
If (! Patrn.exe c (s) return false
Return true
}
// Verify the search keyword
Copy codeThe Code is as follows:
Function isSearch (s)
{
Var patrn =/^ [^ '~! @ # $ % ^ & * () + = |\\] [\] \{\}:;' \,. <>/?] {1} [^ '~! @ $ % ^ & () + = |\\]
[\] \{\}:; '\,. <>?] {0, 19} $ /;
If (! Patrn.exe c (s) return false
Return true
}
Function isIP (s) // by zergling
{
Var patrn =/^ [0-9.] {1, 20} $ /;
If (! Patrn.exe c (s) return false
Return true
}
Getting started with regular expressions in 30 minutes
Basic Regular Expressions