js commonly used in regular expressions

Reprinted: https://www.cnblogs.com/ajuan/p/10791553.html#_label0_0

 


1 Overview

1.1 Description

In the course of the project, and sometimes you need to use regular expressions to validate some input information, so these regular expressions recorded for later use.

 2. Code

Code Example 2.1

2.1.1 regular ID card

1
const reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/

2.1.2 Digital Regular

1
const reg = /[0-9]/

2.1.3 English Regular

const reg = /^[a-z]+$/i

2.1.4 Chinese Regular

const reg = /[\u4e00-\u9fa5]/gm

2.1.5 Digital comma regular

const reg = /^[\d,]*$/

2.1.6 Special regular characters

// special English characters 
const REGEN = /[`~!@#$%^&*()_+<>?:"{},\\.\/;'[\]]/im 
// Chinese special characters 
const regCn = /[·!#¥(--):;""',,|"."?,【】[\]]/im

2.1.7 regular phone number

1
const reg = /^[1][3,4,5,7,8][0-9]{9}$/

2.1.8 regular license plate number

Copy the code
// New Energy length. 8 
const XREG = / ^ [Beijing, Tianjin Liaoning black cloud Yu Ji Yu Lu Xin Wan Xiang Su Zhegan E Gui Shan Gan Jin Meng Ji Min Chuan Ningqiong so expensive Guangdong Qingzang collar AZ] {1} [AZ] { }. 1 (([0-9] {}. 5 [the DF] $) | ([the DF] [HJ-the NP-A-Z0-9] [0-9] {} $. 4)) / 
// conventional plate length is. 7 
const CREG = / ^ [Beijing, Tianjin Liaoning black cloud Yu Ji Yu Lu Xin Wan Xiang Su Zhegan E Gui Shan Gan Jin Meng Ji Min Chuan Ningqiong so expensive Guangdong Qingzang collar AZ] {1} [AZ] {1} [A- HJ-NP-Z0-9] {4 } [A-HJ-NP-Z0-9 hanging recruits Macau] {1} $ / 
Copy the code

2.1.9 English special regular characters

Rain = const /[`~!@#$%^&*()_+<>?:"{},\\.\/;'[\]]/im

2.2.0 Chinese special regular characters

const regCn = /[·!#¥(——):;“”‘、,|《。》?、【】[\]]/im

 

  

Guess you like

Origin www.cnblogs.com/ConfidentLiu/p/12117181.html