Only numbers are allowed: "^ [0-9] * $ ".
Only n digits can be entered: "^ \ D {n} $ ".
You can only enter at least N digits: "^ \ D {n,} $ ".
Only M ~ can be input ~ N-digit :. "^ \ D {m, n} $"
Only numbers starting with zero and non-zero can be entered: "^ (0 | [1-9] [0-9] *) $ ".
Only positive numbers with two decimal places can be entered: "^ [0-9] + (. [0-9] {2 })? $ ".
Only 1 ~ Positive number of three decimal places: "^ [0-9] + (. [0-9] {1, 3 })? $ ".
Only a non-zero positive integer can be entered: "^ \ +? [1-9] [0-9] * $ ".
Only a non-zero negative integer can be entered: "^ \-[1-9] [] 0-9" * $.
Only 3 characters can be entered: "^. {3} $ ".
You can only enter a string consisting of 26 English letters: "^ [A-Za-Z] + $ ".
You can only enter a string consisting of 26 uppercase letters: "^ [A-Z] + $ ".
You can only enter a string consisting of 26 lower-case English letters: "^ [A-Z] + $ ".
You can only enter a string consisting of a number and 26 English letters: "^ [A-Za-z0-9] + $ ".
You can only enter a string consisting of digits, 26 English letters, or underscores (_): "^ \ W + $ ".
Verify the User Password: "^ [A-Za-Z] \ W {5, 17} $". The correct format is: start with a letter, with a length of 6 ~ It can only contain characters, numbers, and underscores.
Check whether ^ % & ',; =? $ \ "And other characters:" [^ % & ',; =? $ \ X22] + ".
Only Chinese characters can be entered: "^ [\ u4e00-\ u9fa5] {0,} $"
Verify email address: "^ \ W + ([-+.] \ W +) * @ \ W + ([-.] \ W + )*\. \ W + ([-.] \ W +) * $ ".
Verify interneturl: "^ http: // ([\ W-] + \.) + [\ W-] + (/[\ W -./? % & =] *)? $ ".
Verification phone number: "^ (\ D {3, 4}-) | \ D {3.4 }-)? \ D {7,8} $ "correct format:" XXX-XXXXXXX "," XXXX-XXXXXXXX "," XXX-XXXXXXX "," XXX-XXXXXXXX "," xxxxxxx "and" XXXXXXXX ".
Verify the ID card number (15 or 18 digits): "^ \ D {15} | \ D {18} $ ".
12 months of verification: "^ (0? [1-9] | 1 [0-2]) $ "the correct format is:" 01 "~ "09" and "1 "~ "12 ".
31 days of verification for a month: "^ (0? [1-9]) | (1 | 2) [0-9]) | 30 | 31) $ "the correct format is;" 01 "~ "09" and "1 "~ "31 ".
Use regular expressions to restrict text box input in a webpage form:
You can only enter Chinese characters using regular expressions: onkeyup = "value = value. replace (/[^ \ u4e00-\ u9fa5]/g, '')" onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[^ \ u4e00-\ u9fa5]/g ,''))"
You can only enter the full-width characters: onkeyup = "value = value. replace (/[^ \ uff00-\ Uffff]/g, '')" onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[^ \ uff00-\ Uffff]/g ,''))"
Use a regular expression to limit that only numbers can be entered: onkeyup = "value = value. replace (/[^ \ D]/g, '')" onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[^ \ D]/g ,''))"
You can only enter numbers and English letters using regular expressions: onkeyup = "value = value. replace (/[\ W]/g, '')" onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[^ \ D]/g ,''))"
-----------------------------------------------------
Length limit
^. {} $4-10 arbitrary string
---------------
Only n characters can be entered
Expression: ^. {n} $ for example, ^. {4} $
Description: Only n characters can be entered. (space, Chinese characters, and special characters are counted as 1 character)
-------------------------------------------------------------------------
Effective String Length
Expression: ^. {1, 50} $
Description: Valid String Length (space, Chinese character, special character, etc. are counted as 1 character)
-----------------------------------------------------------------------
//////////////////////////////////////// ////////////////////////
// Verification number
//////////////////////////////////////// ////////////////////////
------------------------------------------------------------
Only one digit can be entered
Expression: ^ \ D $
Description: match a digit.
Matched: 0, 1, 2, 3
Unmatched: E, 22
----------------------------------------------------------
Only n digits can be entered
Expression: ^ \ D {n} $ for example, ^ \ D {8} $
Description: matches 8 numbers.
Matched: 12345678,22223334, 12344321
Unmatched: E, 22
-------------------------------------------------------------
You can enter at least N numbers.
Expression: ^ \ D {n ,}$ for example, ^ \ D {8,} $
Description: matches at least N digits.
Matching: 12345678,1234567, 123123
------------------------------------------------------------------
Only M to N numbers can be input
Expression: ^ \ D {M, N }$ for example ^ \ D {7, 8} $
Description: It matches numbers ranging from m to n.
Matching: 12345678,1234567
Mismatched: 123456,123456789
------------------------------------------------------------------
Only numbers in a certain range can be entered.
Expression: ^ [12-15] $
Description: only a certain number of characters can be entered.
Matched: 12, 13, 14, 15
Unmatched: 11,16
----------------------------------------------------------------------
Only numbers with 0 and non-0 headers can be entered.
Expression: ^ (0 | [1-9] [0-9] *) $
Description: only numbers with 0 and non-0 headers can be entered.
Matched: 101,100
Unmatched: 01
--------------------------------------------------------------------
^ [0-9] * $
Only numbers (any number) can be entered)
^ \ D + $"
Non-negative integer (positive integer + 0)
^ \ +? [1-9] [0-9] * $
Positive Integer
^ [0-9] * [1-9] [0-9] * $"
Positive Integer
^ (-\ D +) | (0 +) $"
Non-positive integer (negative integer + 0)
^ \-[1-9] [0-9] * $
Negative integer
^-[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
Bytes ------------------------------------------------------------------------------------
Real Number
Expression: ^ [-+]? \ D + (\. \ D + )? $
Description: real number.
Matched: 18, + 3.14,-9.90
Unmatched:. 6, 33 S, 67-99
--------------------------------------------------------------------
Only the positive number of N decimal places can be input
Expression: ^ [0-9] + (. [0-9] {n })? $ For example ^ [0-9] + (. [0-9] {2 })? $
Description: only the positive number of N decimal places can be entered.
Matched: 2.22
Unmatched: 2.222
--------------------------------------------------------------------
Only the positive number of M-N decimal places can be input.
Expression: ^ [0-9] + (. [0-9] {m, n })? $ For example ^ [0-9] + (. [0-9] {1, 2 })? $
Description: only the positive number of M-N decimal places can be entered.
Matching: 2.22, 2.2
Unmatched: 2.222,-2.2222
--------------------------------------------------------------
(^ \ D *\.? \ D * [1-9] + \ D * $) | (^ [1-9] + \ D * \. \ D * $)
Decimal number greater than zero
^ (\ D | -)? (\ D | ,)*\.? \ D * $
Any decimal number, a pure number, a negative number, and a comma-separated numeric point. The decimal format is 5,000-5,000 100.044. 2.
^ (\ D | -)? (\ D | ,)*\.? \ D * $
0-99999999 numbers with or without commas
//////////////////////////////////////// /////////////////////////////////
// Verify the Western characters
//////////////////////////////////////// ////////////////////////////////
^ [A-Za-Z] + $"
String consisting of 26 English letters
^ [A-Z] + $"
A string consisting of 26 uppercase letters.
^ [A-Z] + $"
A string consisting of 26 lower-case letters.
^ [A-Za-z0-9] + $"
String consisting of digits and 26 English letters
^ \ W + $"
String consisting of digits, 26 English letters, or underscores
^. [A-Za-Z] \ W {m, n} $
It must start with an English character and must contain letters, numbers, and underscores (_).
\ B [^ \ Wa-z0-9 _] [^ \ WA-Z0-9 _] * \ B
Only uppercase letters are allowed.
----------------------------------------------------------------------
Two identical words connected together
Expression: (\ W +) \ s + \ 1
Description: two identical words that are connected together.
Matched: ABC
Mismatched: ABC ABCD
-----------------------------------------------------
Words enclosed by double quotation marks
Expression: "(http://www.cnblogs.com/matchcolor/admin/file://%22) % 7C [% 5E % 22 (//)]) +"
Description: The word enclosed in double quotation marks.
Matched:
"ABC"
"ABC" SFF"
Unmatched:
"Sdfsdfsdf
-------------------------------------------------------
//////////////////////////////////////// ////////////
// Specific verification format
//////////////////////////////////////// ////////////
-----------------------------------------------------
Email Address
Expression: ^ [\ W-] + (\. [\ W-] +) * @ [\ W-] + (\. [\ W-] +) + $"
Description: Common verification.
Expression: \ W + ([-+.] \ W +) * @ \ W + ([-.] \ W + )*\. \ W + ([-.] \ W + )*
Description: Microsoft email verification.
Complex expressions: ^ ([^ <>; () [\] \.,;: @ "] + (\. [^ <> () [\] \.,;: @ "] +) *) | (". + ") @ ([A-Z] ([-a-z0-9] * [a-z0-9])?) | (# [0-9] +) | (\ [([01]? [0-9] {0, 2}) | (2 ([0-4] [0-9]) | (5 [0-5]) \.) {3} ([01]? [0-9] {0, 2}) | (2 ([0-4] [0-9]) | (5 [0-5]) \]) \.) * ([A-Z] ([-a-z0-9] * [a-z0-9])?) | (# [0-9] +) | (\ [([01]? [0-9] {0, 2}) | (2 ([0-4] [0-9]) | (5 [0-5]) \.) {3} ([01]? [0-9] {0, 2}) | (2 ([0-4] [0-9]) | (5 [0-5]) \]) $
Description: standard verification email address, all email addresses in the format specified by rfc821 (http://www.cis.ohio-state.edu/cgi-bin/rfc/rfc0821.html # page-30)
Bytes -------------------------------------------------------------------------------------------------
URL Verification
Expression: ^ [A-Za-Z] +: // (\ W + (-\ W + )*)(\. (\ W + (-\ W + )*))*(\? \ S *)? $"
Description: Common URL verification.
Expression: http: // ([\ W-] + \.) + [\ W-] + (/[\ W -./? % & =] *)?
Description: Microsoft URL verification.
Bytes ----------------------------------------------------------------------------------------------
Table Format: [0-9] {5, 9}
Description: QQ number of 5-9 digits
Expression: \ D {18} | \ D {15}
Description: 15-digit, 18-digit ID card number.
Expressiveness: ^ [1-9] ([0-9] {16} | [0-9] {13}) [xX0-9] $
Description: ID card number of 15 or 18 digits. It can contain x characters.
Expression: ^ 13 [0-9] {1} [0-9] {8} | ^ 15 [9] {1} [0-9] {8}
Description: 159-130 mobile phone number included in the package
Expression: (p \ D {7}) | G \ D {8 })
Description: verifies the p + 7 numbers and G + 8 digital passports.
Expression: ^ [a-zA-Z0-9] + ([A-zA-Z0-9 \-\.] + )? \. (COM | org | net | CN | com.cn | edu.cn | grv.cn |) $
Description: verification domain name.
Expression: ^ (d {1, 2} | 1dd | 2 [0-4] d | 25 [0-5]). (d {1, 2} | 1dd | 2 [0-4] d | 25 [0-5]). (d {1, 2} | 1dd | 2 [0-4] d | 25 [0-5]). (d {1, 2} | 1dd | 2 [0-4] d | 25 [0-5]) $"
Description: IP address.
Expression: ^ (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1 -9] {1} [0-9] {1} | [1-9]) \. (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1- 9] {1} [0-9] {1} | [1-9] | 0) \. (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1- 9] {1} [0-9] {1} | [1-9] | 0) \. (25 [0-5] | 2 [0-4] [0-9] | [0-1] {1} [0-9] {2} | [1- 9] {1} [0-9] {1} | [0-9]) $
Description: verification IP address.
Bytes --------------------------------------------------------------------------------------
Credit Card
Expression: ^ [{| \ (]? [0-9a-fa-f] {8} [-]? ([0-9a-fa-f] {4} [-]?) {3} [0-9a-fa-f] {12} [\) |}]? $
Description: A 16-digit number is separated by a hyphen or space.
Matched:
1234343425262837
1111 to 2323-2312-3434
1111 2323 2312 3434
Unmatched:
1111 2323 2312-3434
Expression: ^ ((? : 4 \ D {3}) | (? : 5 [1-5] \ D {2}) | (? : 6011) | (? : 3 [68] \ D {2}) | (? : 30 [012345] \ D) [-]? (\ D {4}) [-]? (\ D {4}) [-]? (\ D {4} | 3 [4, 7] \ D {13}) $
Description: Visa, MasterCard, discover, and US Express.
Bytes --------------------------------------------------------------------------------------------
^ (\ D [-] *) {9} [\ dxx] $ // verify the ISBN international standard number, for example, 7-111-19947-2
^ [A-Z0-9] {8}-[A-Z0-9] {4}-[A-Z0-9] {4}-[A-Z0-9] {4}-[A-Z0-9] {12} $ // verify guid globally Unique Identifier, such as 2064d355-c0b9-41d8-9ef7-9d8b26524751
^ ([A-Za-Z] \: |\\) \ ([^ \] + \) * [^ \/:*? "<> |] + \. Txt (l )? $ // Check the path and file extension E: \ mo.txt error E: \, mo.doc, E: \ mo.doc
Image SRC [^>] * [^/]. (? : JPG | BMP | GIF )(? : \ "| \')
URL "\ <A. +? Href = ['""] (?! HTTP \:\/\/)(?! Mailto \ :) (?> Foundanchor> [^ '">] + ?) [^>] *? \>"
//////////////////////////////////////// ///////////////////////
// Verify Chinese Characters
//////////////////////////////////////// //////////////////////
-------------------------------------------------------------------
Expressiveness: ^ ([\ u4e00-\ u9fa5] + | [a-zA-Z0-9] +) $
Description: Chinese
Expression: [\ u4e00-\ u9fa5]
Description: Chinese characters.
Expression: (/[^ \ u4e00-\ u9fa5]/g
Description: Chinese characters.
Expression: ^ [\ u4e00-\ u9fa5] {0,} $
Description: only Chinese characters are allowed.
Expression: [^ \ x00-\ xFF]
Description: dubyte characters (including Chinese characters)
Expressiveness: \ n [\ s |] * \ r
Description: matches empty rows.
Expression: (^ \ s *) | (\ s * $)
Description: matches spaces at the beginning and end: (TRIM functions like VBScript)
------------------------------------------------------------
Verify hexadecimal color value
Expression: ^ #? ([A-F] | [A-F] | [0-9]) {3} ([A-F] | [A-F] | [0-9]) {3 })? $
Description: It is optional to verify the hexadecimal color value.
Matched:
#00 CCFF
Ffffcc
Unmatched:
Blue
Zero X 000000
-------------------------------------------------------------
//////////////////////////////////////// ///////////////
// Mark related
//////////////////////////////////////// ///////////////
-------------------------------------------------------
Verification HTML Tag
Expression:/<(. *)>. * <\/\ 1> | <(. *) \/>/
Description: matching HTML tags
------------------------------------------------------
Verification mark
Description: All HTML and XML tags.
Expression: <[^>] +>
--------------------------------------------------------------
Mark a pair of closed certificates
Expression: ^ #? ([A-F] | [A-F] | [0-9]) {3} ([A-F] | [A-F] | [0-9]) {3 })? $
Description: verifies a pair of enclosed <> tags.
Matched:
<Body> text <br/> more text </body>
<A href = "link.html"> link </a>
Unmatched:
Blue
Zero X 000000
------------------------------------------------------------
Verify all valid on events in HTML
Expression :(? I: On (blur | C (hange | lick) | dblclick | focus | keypress | (Key | mouse) (down | up) | (un )? Load | mouse (move | O (UT | ver) | reset | S (ELECT | submit )))
Description: verifies all valid on events in HTML.
Matched: onclick onmouseover
Unmatched: click Move
--------------------------------------------------------
Search for comments in HTML
Expression: <! \-\-.*? \->
Description: Search for comments in HTML.
Matched: <! -- <H1> This text has been removed Unmatched: ----------------------------------------------------------------
Find the HTML special file (swf.jpg.gif ...)
Expression: <[^>] * \ n ?. * = ("| ')? (. * \. Jpg) ("| ')?. * \ N? [^ <] *>
Description: Find the special file (swf.jpg.gif…) in HTML ...) Convert JPG to gif to search for all GIF files.
matched:
unmatched: = img.jpg
Other
/////////////////////////////// //// //
// Date and time
/////////////// /// //
restart
^ (\ D {1, 4 }) (-| \/) (\ D {1, 2}) \ 2 (\ D {1, 2 }) $ // Date Format:
/^ (d {2} | D {4})-(0 ([1-9] {1 })) | (1 [1 | 2])-([0-2] ([1-9] {1}) | (3 [0 | 1]) $ // year-month-day
/^ (0 ([1-9] {1}) | (1 [1 | 2]) /([0-2] ([1-9] {1}) | (3 [0 | 1]) /(d {2} | D {4}) $ // month/day/year
YYYY-MM-DD basically takes into account the situation of the Year of the leap and February.
^ (1 [6-9] | [2-9] \ D) \ D {2})-(0? [1, 13578] | 1 [02])-(0? [1-9] | [12] \ d | 3 [01]) | (1 [6-9] | [2-9] \ D) \ D {2})-(0? [13456789] | 1 [012])-(0? [1-9] | [12] \ d | 30) | (1 [6-9] | [2-9] \ D) \ D {2 }) -0? 2-(0? [1-9] | 1 \ d | 2 [0-8]) | (1 [6-9] | [2-9] \ D) (0 [48] | [2468] [048] | [13579] [26]) | (16 | [2468] [048] | [3579] [26]) 00)-0? 2-29-) $
---------------------------------------------------------------
Day Verification
Expression:
^ (? :(? :(? :(? :(? : 1 [6-9] | [2-9] \ D )? (? : 0 [48] | [2468] [048] | [13579] [26]) | (? :(? : 16 | [2468] [048] | [3579] [26]) (\/|-| \.)(? : 0? 2 \ 1 (? : 29) | (? :(? :(? : 1 [6-9] | [2-9] \ D )? \ D {2}) (\/|-| \.)(? :(? :(? : 0? [2, 13578] | 1 [02]) \ 2 (? : 31) | (? :(? : 0? [1, 3-9] | 1 [0-2]) \ 2 (29 | 30) | (? :(? : 0? [1-9]) | (? : 1 [0-2]) \ 2 (? : 0? [1-9] | 1 \ d | 2 [0-8]) $
Description:
Verify the date in the format of Y/M/D from 1600/1/1-9999/12/31
Matched:
04/2/29
2002-4-30
02.10.31
Unmatched:
2003/2/29
02.4.31
00/00/00
-------------------------------------------------------
Combination Date and Time
Expression:
^ (\ D {2} ([02468] [048]) | ([13579] [26]) [\-\/\ s]? (0? [13578]) | (1 [02]) [\-\/\ s]? (0? [1-9]) | ([1-2] [0-9]) | (3 [01]) | (0? [469]) | (11) [\-\/\ s]? (0? [1-9]) | ([1-2] [0-9]) | (30) | (0? 2 [\-\/\ s]? (0? [1-9]) | ([1-2] [0-9]) | (\ D {2} ([02468] [1235679]) | ([13579] [01345789]) [\-\/\ s]? (0? [13578]) | (1 [02]) [\-\/\ s]? (0? [1-9]) | ([1-2] [0-9]) | (3 [01]) | (0? [469]) | (11) [\-\/\ s]? (0? [1-9]) | ([1-2] [0-9]) | (30) | (0? 2 [\-\/\ s]? (0? [1-9]) | (1 [0-9]) | (2 [0-8]) (\ s (0? [0-9]) | ([1-2] [0-3]) \ :( [0-5]? [0-9]) (\ s) | (\ :( [0-5]? [0-9])? $
Description: verify all valid dates and times
matched:
yyyy-mm-DD
hh: mm: SS
yyyy-mm-dd hh: mm: SS
unmatched: 2003/2/29 00/00/00
------------------------------------------------
quasi-ansi SQL date verification
Expression:
^ (\ D {2} ([02468] [048]) | ([13579] [26]) [\-\/\ s]? (0? [13578]) | (1 [02]) [\-\/\ s]? (0? [1-9]) | ([1-2] [0-9]) | (3 [01]) | (0? [469]) | (11) [\-\/\ s]? (0? [1-9]) | ([1-2] [0-9]) | (30) | (0? 2 [\-\/\ s]? (0? [1-9]) | ([1-2] [0-9]) | (\ D {2} ([02468] [1235679]) | ([13579] [01345789]) [\-\/\ s]? (0? [13578]) | (1 [02]) [\-\/\ s]? (0? [1-9]) | ([1-2] [0-9]) | (3 [01]) | (0? [469]) | (11) [\-\/\ s]? (0? [1-9]) | ([1-2] [0-9]) | (30) | (0? 2 [\-\/\ s]? (0? [1-9]) | (1 [0-9]) | (2 [0-8]) (\ s (0? [1-9]) | (1 [0-2]) \ :( [0-5] [0-9]) (\ s) | (\ :( [0-5] [0-9]) \ s) ([am | Pm | am | PM] {2, 2 })))? $
Description:
date format matching ansi SQL: yyyy-mm-dd hh: mm: SS AM/PM includes checking whether the period from is a leap year.
matching:
10:29:39
unmatched
04-2-29
04-02-29 10:29:39
04/12/31
-----------------------------------------------------
///////////////////////////// //// //
// other
///// //////////////////////////////////////// /// //
------------------------------------------------------------------
match font
Expression: ^ (\ D) * (PX | Px | Pt |) $
Description: Search for the font suffix.
Matched:
1px
100 PT
20px
Unmatched: 1abc, PX, 1, sdfs
-------------------------------------------------------------
Match the MD5 Hashi string
Expression: ^ ([a-z0-9] {32}) $
Description: matches the MD5 Hashi string.
Matched: 790d2cf6ada1937417c17f1ef41ab125
Mismatched: 790d2cf6ada1937417c17f1ef41ab125
---------------------------------------------------------------------------
The following is an example:
Use regular expressions to restrict text box input in a webpage form:
You can only enter Chinese characters using regular expressions: onkeyup = "value = value. replace (/[^ \ u4e00-\ u9fa5]/g, '')" onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[^ \ u4e00-\ u9fa5]/g ,''))"
1. you can only enter the full-width characters: onkeyup = "value = value. replace (/[^ \ uff00-\ Uffff]/g, '')" onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[^ \ uff00-\ Uffff]/g ,''))"
2. use a regular expression to limit that only numbers can be entered: onkeyup = "value = value. replace (/[^ \ D]/g, '')" onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[^ \ D]/g ,''))"
3. you can only enter numbers and English letters using regular expressions: onkeyup = "value = value. replace (/[\ W]/g, '')" onbeforepaste = "clipboardData. setdata ('text', clipboardData. getdata ('text '). replace (/[^ \ D]/g ,''))"
4. Calculate the length of a string (two-byte length: 2, ASCII character: 1)
String. Prototype. Len = function () {return this. Replace ([^ \ x00-\ xFF]/g, "AA"). length ;}
5. JavaScript does not have trim functions like VBScript. We can use this expression to implement it, as shown below:
String. Prototype. Trim = function ()
{
Return this. Replace (/(^ \ s *) | (\ s * $)/g ,"");
}
Use regular expressions to break down and convert IP addresses:
6. the following uses a regular expression to match an IP address and convert the IP address to a corresponding JavascriptProgram:
Function ip2v (IP)
{
Re =/(\ D +) \. (\ D +)/g // Regular Expression matching IP addresses
If (Re. Test (IP ))
{
Return Regexp. $1 * Math. Pow (255) + Regexp. $2 * Math. Pow () + Regexp. $3 * + Regexp. $4*1
}
Else
{
Throw new error ("not a correct IP address! ")
}
}
It is easier to directly use the split function to break down programs without regular expressions. The program is as follows:
VaR IP = "10.100.0000168"
IP = IP. Split (".")
Alert ("the IP value is: "+ (IP [0] * 255*255*255 + IP [1] * 255*255 + IP [2] * 255 + IP [3] * 1 ))
(? <=>) [^>] * (? = <)
Javascript programs that extract file names from URLs using regular expressions. the following result is page1.
The following is a reference clip:
S = "http://www.9499.net/page1.htm"
S = S. Replace (/(. * \/) {0,} ([^ \.] +). */ig, "$2 ")
Alert (s)
Match double-byte characters (including Chinese characters): [^ \ x00-\ xFF]
Application: Calculate the length of a string (two-byte length Meter 2, ASCII character meter 1)
The following is a reference clip:
String. Prototype. Len = function () {return this. Replace ([^ \ x00-\ xFF]/g, "AA"). length ;}
Regular Expression for matching empty rows: \ n [\ s |] * \ r
Regular Expressions matching HTML tags:/<(. *)>. * <\/\ 1> | <(. *) \/>/
Regular Expression matching spaces at the beginning and end: (^ \ s *) | (\ s * $)
The following is a reference clip:
String. Prototype. Trim = function ()
{
Return this. Replace (/(^ \ s *) | (\ s * $)/g ,"");
}
Use regular expressions to break down and convert IP addresses:
The following is a javascript program that uses regular expressions to match IP addresses and convert IP addresses to corresponding values:
The following is a reference clip:
Function ip2v (IP)
{
Re =/(\ D +) \. (\ D +)/g // Regular Expression matching IP addresses
If (Re. Test (IP ))
{
Return Regexp. $1 * Math. Pow (255) + Regexp. $2 * Math. Pow () + Regexp. $3 * + Regexp. $4*1
}
Else
{
Throw new error ("not a valid IP address! ")
}
}
However, if the above program does not use regular expressions, it may be easier to directly use the split function to separate them. The program is as follows:
The following is a reference clip:
var IP = "10.100.0000168"
IP = IP. split (". ")
alert (" the IP value is: "+ (IP [0] * 255*255*255 + IP [1] * 255*255 + IP [2] * 255 + IP [3] * 1 ))