Add 150,153,156,158,159,157,188,189
The regular expression is as follows: ^ (13 [0-9] | 15 [0 | 3 | 6 | 7 | 8 | 9] | 18 [8 | 9]) \ D {8 }$ // 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
}
// Check user name: only 1-30 strings starting with letters can be entered
Function istruename (s)
{
VaR patrn =/^ [A-Za-Z] {1, 30} $ /;
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 phone number and fax number. The phone number can start with "+" and contain "-" in addition to numbers.
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.
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
Function ispostalcode (s)
{
// Var patrn =/^ [a-zA-Z0-9] {3, 12} $ /;
VaR patrn =/^ [a-zA-Z0-9] {} $ /;
If (! Patrn.exe C (s) return false
Return true
}
// Verify the search keyword
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
}
Regular Expression
"^ // D + $" // non-negative integer (positive integer + 0)
"^ [0-9] * [1-9] [0-9] * $" // positive integer
"^ (-// D +) | (0 +) $" // non-positive integer (negative integer + 0)
"^-[0-9] * [1-9] [0-9] * $" // negative integer
"^ -? // D + $ "// integer
"^/D + (//. // D + )? $ "// Non-negative floating point number (Positive floating point number + 0)
"^ ([0-9] + //. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] * //. [0-9] +) | ([0-9] * [1-9] [0-9] *) $ "// Positive floating point number
"^ (-/D + (//. // D + )?) | (0 + (//. 0 + )?)) $ "// Non-Positive floating point number (negative floating point number + 0)
"^ (-([0-9] + //. [0-9] * [1-9] [0-9] *) | ([0-9] * [1-9] [0-9] * //. [0-9] +) | ([0-9] * [1-9] [0-9] *) $ "// negative floating point number
"^ (-? // D +) (//. // D + )? $ "// Floating point number
"^ [A-Za-Z] + $" // a string consisting of 26 English letters
"^ [A-Z] + $" // a string consisting of 26 uppercase letters
"^ [A-Z] + $" // a string consisting of 26 lowercase letters
"^ [A-Za-z0-9] + $" // string consisting of digits and 26 letters
"^ // W + $" // a string consisting of digits, 26 English letters, or underscores
"^ [// W-] + (//. [// w-] +) * @ [// w-] + (//. [// w-] +) + $ "// email address
"^ [A-Za-Z] +: // (// W + (-/W + )*)(//. (// W + (-/W + )*))*(//? // S *)? $ "// URL
"^ [A-Za-z0-9 _] * $"
Detailed explanation of Regular Expressions
The regular expression format is generally as follows:
/Love/the part between the "/" delimiters is the pattern to be matched in the target object. You only need to place the pattern content of the desired matching object between the "/" delimiters. To enable users to customize the mode content more flexibly, regular expressions provide special "metacharacters ". Metacharacters are special characters that have special meanings in regular expressions. They can be used to specify the mode in which the leading character (that is, the character located before the metacharacters) appears in the target object.
Frequently Used metacharacters include "+", "*", and "?".
The "+" metacharacter specifies that its leading character must appear one or more times consecutively in the target object.
The "*" metacharacter specifies that the leading character must appear zero or multiple times in the target object.
"?" Metacharacter specifies that the leading object must appear zero or once consecutively in the target object.
Next, let's take a look at the specific application of the regular expression metacharacters.
/FO +/because the regular expression above contains the "+" metacharacter, it can be used with the "fool", "FO ", or "football", and so on, one or more character strings that match the letter "F" consecutively.
/EG */because the above regular expression contains "*" metacharacters, it can be used with "easy", "ego ", or, "egg" and other strings that appear after the letter E are matched with zero or multiple Letter g consecutively.
/Wil? /Because the above regular expression contains "?" Metacharacter, indicating that it can match the "win" or "Wilson" in the target object, and matches zero or one character string after the letter I.
Sometimes I don't know how many characters to match. To adapt to this uncertainty, regular expressions support the concept of delimiters. These qualifiers can specify how many times a given component of a regular expression must appear to match.
{N} n is a non-negative integer. Match n times. For example, 'O {2} 'cannot match 'O' in "Bob", but can match two o in "food.
{N,} n is a non-negative integer. Match at least N times. For example, 'O {2,} 'cannot match 'O' in "Bob", but can match all o in "foooood. 'O {1,} 'is equivalent to 'o + '. 'O {0,} 'is equivalent to 'o *'.
Both {n, m} m and n are non-negative integers, where n <= m. Match at least N times and at most m times. For example, "O {1, 3}" matches the first three o in "fooooood. 'O {0, 1} 'is equivalent to 'o? '. Note that there must be no space between a comma and two numbers.
In addition to metacharacters, you can also precisely specify the frequency of occurrence of a pattern in a matching object. For example, the/Jim {}/regular expression specifies that the character m can appear 2-6 times in a row in the matching object. Therefore, the regular expression can match strings such as Jimmy or jimmmmmy.
After a preliminary understanding of how to use regular expressions, let's take a look at the usage of several other important metacharacters.
/S: Used to match a single space character, including the tab key and line break;
/S: Used to match all characters except a single space character;
/D: Used to match numbers from 0 to 9;
/W: Used to match letters, numbers, or underscores;
/W: Used to match all characters that do not match/W;
.: Used to match all characters except line breaks.
(Note: we can regard/s and/W and/w as inverse operations)
Next, let's take a look at how to use the above metacharacters in regular expressions through examples.
// S +/the above regular expression can be used to match one or more space characters in the target object.
/// D000/if we have a complex financial statement in hand, we can easily find all the total amount of RMB through the above regular expression.
In addition to the metacharacters described above, regular expressions also have a unique special character, that is, the positioning character. Specifies the position where the matching mode appears in the target object. Commonly used positioning symbols include "^", "$", "/B", and "/B ".
The "^" Locator specifies that the matching mode must start with the target string.
The "$" operator specifies that the matching mode must appear at the end of the target object.
The "/B" Locator specifies that the matching mode must appear at the beginning or end of the target string.
The "/B" Locator specifies that the matched object must be within the boundary of the start and end of the target string. That is, the matched object cannot start with the target string, it cannot end with the target string. Similarly, we can regard "^" and "$" as well as "/B" and "/B" as two sets of operators for inverse operation. For example:/^ hell/because the above regular expression contains the "^" locator, you can use "hell" with the target object ", the string starting with "hello" or "Hellhound" matches. /AR $/because the regular expression above contains the "$" operator, it can match the string ending with "car", "bar", or "Ar" in the target object.
// Bbom/because the above regular expression pattern starts with "/B", it can match a string starting with "bomb" or "Bom" in the target object. /Man/B/because the above regular expression pattern ends with a "/B" positioning character, you can use "human" with the target object ", the string ending with "woman" or "man" matches.
To make it easier for users to set matching modes flexibly, regular expressions allow users to specify a range in the matching mode, not limited to specific characters. For example:
/[A-Z]/the above regular expression will match any uppercase letter from A to Z.
/[A-Z]/the above regular expression will match any lowercase letter in the range from A to Z.
/[0-9]/the above regular expression will match any number from 0 to 9.
/([A-Z] [A-Z] [0-9]) +/the above regular expression will be associated with any string consisting of letters and numbers, for example, "ab0" matches. Note that you can use "()" in a regular expression to combine strings. The content contained by the "()" symbol must appear in the target object at the same time. Therefore, the above regular expression cannot match strings such as "ABC", because the last character in "ABC" is a letter rather than a number.
If we want to implement the "or" operation similar to the programming logic in the regular expression, and select one of multiple different modes for matching, we can use the pipe character "| ". For example:/to | too | 2/the above regular expression will match "to", "too", or "2" in the target object.
There is also a common operator in the regular expression, that is, the negative character "[^]". Unlike the positioning character "^" described above, the "[^]" negation specifies that the target object cannot contain strings specified in the pattern. For example:/[^ A-C]/the above string will match any character except A, B, and C in the target object. In general, when "^" appears in "[]", it is regarded as a negative operator. When "^" is located outside of "[]" or, it should be regarded as a positioning character.
Finally, you can use the Escape Character "/" to add metacharacters to the regular expression mode and find matching objects. For example, the/Th/*/regular expression will match the "th *" in the target object rather than ".
After constructing a regular expression, you can evaluate the value like a mathematical expression, that is, you can evaluate the value from left to right in a priority order. The priority is as follows:
1./Escape Character
2 .(),(? :),(? =), [] Parentheses and square brackets
3. *, + ,?, {N}, {n ,}, {n, m} qualifier
4. ^, $,/anymetacharacter location and Sequence
5. | "or" Operation reproduced in: http://www.cnblogs.com/showjhappyb/archive/2008/12/17/499975.html