web front-end articles: JavaScript regular expression (3) commonly used in regular match

Domestic matching telephone number: \ d {3} - \ d {8} | \ d {4} - \ d {7}

As 0511-4405222 or 021-87888822

Match QQ: [1-9] [0-9] {4}

10000 from the beginning

Postal Code: [1-9] \ d {5} (?! \ D)

6-digit postal code

Match ID: / ^ (\ d {14} | \ d {17}) (\ d | [xX]) $ /

Matching rules: identity card numbers have 15 or 18, which may be the last one X, all other digital
Click to receive free information and courses

Ip address match:... \ D + \ d + \ d + \ d +

Matching account is valid (starting with the letter, allowing 5-16 bytes to allow alphanumeric underlined): . 1 [A-zA-Z0-9 _] {4,15} $ form validation very useful when

Matching Chinese characters: / [\ u4E00- \ u9FA5 \ uf900- \ ufa2d] /

Use Unicode, you must begin with \ u, followed by four hexadecimal character encoding forms

Matching Email Address:

/^([a-zA-Z_0-9-])+@([a-zA-Z_0-9-])+(.[a-zA-Z_0-9-])+$/

E-mail rule is: consists of three parts

A plurality of alphanumeric or bar + @ + and underscores a plurality of alphanumeric or underscore and the bar +. + 1 or more alphanumeric and the bar underscores

Match URLs URL: [a-zA-z] +: // [^ \ s] *

Is determined not by the string of numbers: / ^ \ d * $ /

Limiting the text box only numbers and decimal points (two decimal places):

/^\d*.?\d{0,2}$/

Description: the beginning of zero or more digits (0 or more times indicates a match before?) Intermediate zero or a decimal point and zero or decimal numbers up to 2

Regular Username: / 2 {4,16} $ /

Matching rule: only Chinese, English, numbers, underscores, 4-16 characters

Chinese characters matching the regular: / [\ u4E00- \ u9FA5 \ uf900- \ ufa2d] /

\ W match is English, numbers, underscores

English matching address: / 3 [.a-zA-the Z-\ S, 0-9] * [A-zA-the Z-] + / matches the rule:? Contains point, letters, spaces, commas, numbers, it must be the beginning and end analysis letters: would write must begin with the letter / [a-zA-Z] / end must be able to write letters: / [a-zA-Z ] + /

Intermediate points include letters, spaces, commas, numbers of regular: [. A-zA-the Z-\ S, 0-9] / ? /
Click to receive free information and courses
outside
number is zero or more, after the question mark ? represents the dispensable; there will match, no do not match;

Matching price:? / ^ \ D * (. \ D {0,2}) $ /

Matching rules: at the beginning of zero or more digits, the middle may have a decimal point and there may decimals 0-2

The first letter of the word capitalized: / \ b (\ w) | \ s (\ w) / g

Date format verification: / ^ \ d {4} [- /] \ d {1,2} [- /] \ d {1,2} $ /

Date formats are two types of first one is or yyyy-mm-dd yyyy / mm / dd

Analysis: months, and days can have a two or


  1. -zA-a Z ↩︎

  2. \ u4E00- \ u9FA5 \ uf900- \ ufa2d \ w ↩︎

  3. -zA-a Z ↩︎

Guess you like

Origin blog.csdn.net/ITmiaomiao666/article/details/92010531