First, the check digit of expression
digital
^[0-9]\*$
复制代码
n-bit numbers:
^\d{n}$
复制代码
At least n-bit numbers:
^\d{n,}$
复制代码
mn digits:
^\d{m,n}$
复制代码
Zero and non-zero number that begins:
^(0|[1-9][0-9]\*)$
复制代码
With up to two decimal places beginning with a non-zero:
^([1-9][0-9]\*)+(\.[0-9]{1,2})?$
复制代码
Decimals with 1-2 positive or negative:
^(\-)?\d+(\.\d{1,2})$
复制代码
Positive, negative, and decimals:
^(\-|\+)?\d+(\.\d+)?$
复制代码
There are two positive real number of decimal places:
^[0-9]+(\.[0-9]{2})?$
复制代码
1 to 3 a positive real number of decimal places:
^[0-9]+(\.[0-9]{1,3})?$
复制代码
Non-zero positive integers:
^[1-9]\d\*$ 或 ^([1-9][0-9]\*){1,3}$ 或 ^\+?[1-9][0-9]\*$
复制代码
Non-zero-negative integers:
^\-[1-9][]0-9"\*$ 或 ^-[1-9]\d\*$
复制代码
Non-negative integers:
^\d+$ 或 ^[1-9]\d\*|0$
复制代码
Non-positive integers:
^-[1-9]\d\*|0$ 或 ^((-\d+)|(0+))$
复制代码
Non-negative floating-point numbers:
^\d+(\.\d+)?$ 或 ^[1-9]\d\*\.\d\*|0\.\d\*[1-9]\d\*|0?\.0+|0$
复制代码
Non-positive float:
^((-\d+(\.\d+)?)|(0+(\.0+)?))$ 或 ^(-([1-9]\d\*\.\d\*|0\.\d\*[1-9]\d\*))|0?\.0+|0$
复制代码
Positive 浮点 number:
^[1-9]\d\*\.\d\*|0\.\d\*[1-9]\d\*$
或
^(([0-9]+\.[0-9]\*[1-9][0-9]\*)|([0-9]\*[1-9][0-9]\*\.[0-9]+)|([0-9]\*[1-9][0-9]\*))$
复制代码
负浮 points:
^-([1-9]\d\*\.\d\*|0\.\d\*[1-9]\d\*)$
或
^(-(([0-9]+\.[0-9]\*[1-9][0-9]\*)|([0-9]\*[1-9][0-9]\*\.[0-9]+)|([0-9]\*[1-9][0-9]\*)))$
复制代码
Float:
^(-?\d+)(\.\d+)?$ 或 ^-?([1-9]\d\*\.\d\*|0\.\d\*[1-9]\d\*|0?\.0+|0)$
复制代码
Second, check character expression
Chinese character:
^[\u4e00-\u9fa5]{0,}$
复制代码
English and figures:
^[A-Za-z0-9]+$ 或 ^[A-Za-z0-9]{4,40}$
复制代码
Length of all characters 3-20:
^.{3,20}$
复制代码
26 letters of the English string:
^[A-Za-z]+$
复制代码
The 26 uppercase letters of the English string:
^[A-Z]+$
复制代码
Write letters composed by the 26 small string:
^[a-z]+$
复制代码
By the numeral 26 and letters of the English string:
^[A-Za-z0-9]+$
复制代码
Digital, 26 English letters or underscore character string:
^\w+$ 或 ^\w{3,20}$
复制代码
Chinese, English, numbers, including underscore:
^[\u4E00-\u9FA5A-Za-z0-9_]+$
复制代码
Chinese, English, numbers and other symbols but does not include underscore:
^[\u4E00-\u9FA5A-Za-z0-9]+$ 或 ^[\u4E00-\u9FA5A-Za-z0-9]{2,20}$
复制代码
Prohibition of input characters contained ~:
[^~\x22]+
复制代码
Third, the special needs of expression
Email Address:
^\w+([-+.]\w+)\*@\w+([-.]\w+)\*\.\w+([-.]\w+)\*$
复制代码
domain name:
[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(/.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+/.?
复制代码
InternetURL:
[a-zA-z]+://[^\s]\* 或 ^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]\*)?$
复制代码
cellphone number:
^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$
复制代码
Domestic phone number (0511-4405222,021-87888822):
\d{3}-\d{8}|\d{4}-\d{7}
复制代码
Phone number regular expression (support phone number, area code 3-4, 7-8 live numbers, 1-4 extension):
((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)
复制代码
ID number (15, 18 digits), the last digit is a check digit, numbers or characters may be X:
(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)
复制代码
Account is valid (beginning with the letter, allow 5-16 bytes, allowing alphanumeric underlined):
^[a-zA-Z][a-zA-Z0-9_]{4,15}$
复制代码
Password (start with a letter, a length between 6 and 18, can contain letters, numbers and underscores):
^[a-zA-Z]\w{5,17}$
复制代码
Strong passwords (which must contain a combination of uppercase and lowercase letters and numbers, special characters can not be used, a length of between 8 and 10):
^(?=.\*\d)(?=.\*[a-z])(?=.\*[A-Z])[a-zA-Z0-9]{8,10}$
复制代码
Strong passwords (which must contain a combination of uppercase and lowercase letters and numbers, special characters may be used, a length of between 8 and 10):
^(?=.\*\d)(?=.\*[a-z])(?=.\*[A-Z]).{8,10}$
复制代码
Date Format:
^\d{4}-\d{1,2}-\d{1,2}
复制代码
Year 12 months (01 ~ 09 and 1 to 12):
^(0?[1-9]|1[0-2])$
复制代码
Month of 31 days (01 ~ 09 and 1 to 31):
^((0?[1-9])|((1|2)[0-9])|30|31)$
复制代码
xml file:
^([a-zA-Z]+-?)+[a-zA-Z0-9]+\\.[x|X][m|M][l|L]$
复制代码
Chinese characters in regular expressions:
[\u4e00-\u9fa5]
复制代码
N blank lines of expression:
\n\s\*\r (可以用来删除空白行)
复制代码
HTML markup regular expression:
<(\S\*?)[^>]\*>.\*?|<.\*? />
复制代码
And last whitespace regular expression:
^\s\*|\s\*$
或
(^\s\*)|(\s\*$)
可以用来删除行首行尾的空白字符(包括空格、制表符、换页符等等),非常有用的表达式
复制代码
Tencent QQ:
[1-9][0-9]{4,} (腾讯QQ号从10000开始)
复制代码
China Postal Code:
[1-9]\d{5}(?!\d) (中国邮政编码为6位数字)
复制代码
IP Address:
((?:(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d?\\d))
复制代码
Reproduced in: https: //juejin.im/post/5d02ff295188256073338572