正则速查表
# 账号&密码相关
# '手机号(mobile phone)中国(严谨), 根据工信部 2019 年最新公布的手机号段',
js /^(?:(?:\+|00)86)?1(?:(?:3[\d)|(?:4[5-79)|(?:5[0-35-9)|(?:6[5-7)|(?:7[0-8)|(?:8[\d)|(?:9[189))\d8}$/
示例:'008618311006933', '+8617888829981', '19119255642'
# '手机号(mobile phone)中国(宽松), 只要是 13,14,15,16,17,18,19 开头即可',
js /^(?:(?:\+|00)86)?1[3-9\d9}$/
示例:'008618311006933', '+8617888829981', '19119255642'
# '手机号(mobile phone)中国(最宽松), 只要是 1 开头即可, 如果你的手机号是用来接收短信, 优先建议选择这一条',
js /^(?:(?:\+|00)86)?1\d10}$/
示例:'008618311006933', '+8617888829981', '19119255642'
# 'email(邮箱)',
js /^(([^<>()[\\\.,;:\s@"+(\.[^<>()[\\\.,;:\s@"+)*)|(".+"))@((\[[0-91,3}\.[0-91,3}\.[0-91,3}\.[0-91,3}\)|(([a-zA-Z\-0-9+\.)+[a-zA-Z2,}))$/
示例:'90203918@qq.com', 'nbilly@126.com'
# '帐号是否合法(字母开头,允许 5-16 字节,允许字母数字下划线组合'
js /^[a-zA-Z\w4,15}$/
示例:'justin', 'justin1989', 'justin_666'
# '用户名校验,4 到 16 位(字母,数字,下划线,减号)',
js /^[a-zA-Z0-9_-4,16}$/
示例:'xiaohua_qq'
# '数字和字母组成',
js /^[A-Za-z0-9+$/
示例:'james666', 'haha233hi'
# '密码强度校验,最少 6 位,包括至少 1 个大写字母,1 个小写字母,1 个数字,1 个特殊字符',
js /^\S*(?=\S6,})(?=\S*\d)(?=\S*[A-Z)(?=\S*[a-z)(?=\S*[!@#$%^&*? )\S*$/
示例:'Kd@curry666'
# '微信号(wx),6 至 20 位,以字母开头,字母,数字,减号,下划线'
js /^[a-zA-Z[-_a-zA-Z0-95,19}$/
示例:'github666', 'kd_-666'
# 'qq 号格式正确',
js /^[1-9[0-94,10}$/
**示例:**903013545, 9020304
# 银行相关
# '身份证号(1 代,15 位数字)',
js /^[1-9\d7}(?:0\d|10|11|12)(?:0[1-9|[1-2[\d|30|31)\d3}$/
示例:'123456991010193'
# '身份证号(2 代,18 位数字),最后一位是校验位,可能为数字或字符 X',
js /^[1-9\d5}(?:18|19|20)\d2}(?:0[1-9|10|11|12)(?:0[1-9|[1-2\d|30|31)\d3}[\dXx$/
示例:'12345619991205131x'
# '身份证号, 支持 1/2 代(15 位/18 位数字)',
js /(^\d8}(0\d|10|11|12)([0-2\d|30|31)\d3}$)|(^\d6}(18|19|20)\d2}(0[1-9|10|11|12)([0-2\d|30|31)\d3}(\d|X|x)$)/
示例:'622223199912051311'
# '护照(包含香港、澳门)',
js /(^[EeKkGgDdSsPpHh\d8}$)|(^(([Ee[a-fA-F)|([DdSsPp[Ee)|([Kk[Jj)|([Mm[Aa)|(1[45))\d7}$)/
示例:'s28233515', '141234567', '159203084', 'MA1234567', 'K25345719'
# '香港身份证 ',
js /^[a-zA-Z\d6}\([\dA\)$/
示例:'K034169(1)'
# '澳门身份证 ',
js /^[1|5|7\d6}[(\d)3}$/
示例:'5686611(1)'
# '台湾身份证 ',
js /^[a-zA-Z[0-99}$/
示例:'U193683453'
# '银行卡号(10 到 30 位, 覆盖对公/私账户, 参考[微信支付(https://pay.weixin.qq.com/wiki/doc/api/xiaowei.php?chapter=22_1))',
js /^[1-9\d9,29}$/
**示例:**6234567890, 6222026006705354217
# '邮政编码(中国)',
js /^(0[1-7|1[0-356|2[0-7|3[0-6|4[0-7|5[1-7|6[1-7|7[0-5|8[013-6)\d4}$/
示例:'734500', '100101'
# '统一社会信用代码',
js /^[0-9A-HJ-NPQRTUWXY2}\d6}[0-9A-HJ-NPQRTUWXY10}$/
示例:'91230184MA1BUFLT44', '92371000MA3MXH0E3W',
# '统一社会信用代码(宽松匹配)(15 位/18 位/20 位数字/字母)',
js /^(([0-9A-Za-z15})|([0-9A-Za-z18})|([0-9A-Za-z20}))$/
示例:'91110108772551611J', '911101085923662400'
# 数字相关
# '小数',
js /^\d+\.\d+$/
示例:'0.0', '0.09'
# '数字',
js /^\d1,}$/
**示例:**12345678
# '股票代码(A 股)'
js /^(s[hz|S[HZ)(000[\d3}|002[\d3}|300[\d3}|600[\d3}|60[\d4})$/
示例:'sz000858', 'SZ002136', 'sz300675', 'SH600600', 'sh601155'
# '数字/货币金额(支持负数、千分位分隔符)'
js /^-?\d+(,\d3})*(\.\d1,2})?$/
**示例:**100, -0.99, 3, 234.32, -1, 900, 235.09, '12,345,678.90'
# '数字/货币金额 (只支持正数、不支持校验千分位分隔符)'
js /(?:^[1-9([0-9+)?(?:\.[0-91,2})?$)|(?:^(?:0)$)|(?:^[0-9\.[0-9(?:[0-9)?$)/
**示例:**0.99, 8.99, 666
# 网络&地址相关
# 'mac 地址',
js /^((([a-f0-92}:)5})|(([a-f0-92}-)5}))[a-f0-92}$/i
,
示例:'38:f9:d3:4b:f5:51', '00-0C-29-CA-E4-66'
# '视频(video)链接地址(视频格式可按需增删)',
js /^https?:\/\/(.+\/)+.+(\.(swf|avi|flv|mpg|rm|mov|wav|asf|3gp|mkv|rmvb|mp4))$/i
示例:'http://www.abc.com/video/wc.avi'
# '图片(image)链接地址(图片格式可按需增删)'
**示例:**'https://www.abc.com/logo.png'
### '必须带端口号的网址(或 ip)'
javascript /^((ht|f)tps?😕/)?[\w-+(.[\w-+)+:\d1,5}/?$/
**示例:**
```'https://www.qq.com:8080', '127.0.0.1:5050', 'baidu.com:8001', 'http://192.168.1.1:9090', '192.168.1.1', 'https://www.jd.com'```
### '网址(url,支持端口和"?+参数"和"#+参数)'
```js /^(((ht|f)tps?):\/\/)?[\w-+(\.[\w-+)+([\w.,@?^=%&:/~+#-*[\w@?^=%&/~+#-)?$/```
**示例:**
```'www.qq.com', 'https://baidu.com', '360.com:8080/vue/#/a=1&b=2',
# '迅雷链接',
js /^thunderx?:\/\/[a-zA-Z\d+=$/
示例: 'thunder://QUEsICdtYWduZXQ6P3h0PXVybjpidGloOjBCQTE0RTUxRkUwNjU1RjE0Qzc4NjE4RjY4NDY0QjZFNTEyNjcyOUMnWlo='
# 'ed2k 链接(宽松匹配)',
js /^ed2k:\/\/\|file\|.+\|\/$/
示例: 'ed2k://|file|%E5%AF%84%E7%94%9F%E8%99%AB.PARASITE.2019.HD-1080p.X264.AAC-UUMp4(ED2000.COM).mp4|2501554832|C0B93E0879C6071CBED732C20CE577A3|h=5HTKZPQFYRKORN52I3M7GQ4QQCIHFIBV|/'
# '磁力链接(宽松匹配)',
js /^magnet:\?xt=urn:btih:[0-9a-fA-F40,}.*$/
示例: 'magnet:?xt=urn:btih:40A89A6F4FB1498A98087109D012A9A851FBE0FC'
# '子网掩码',
js /^(?:\d1,2}|1\d\d|2[0-4\d|25[0-5)(?:\.(?:\d1,2}|1\d\d|2[0-4\d|25[0-5))3}$/
示例:'255.255.255.0', '255.224.0.0'
# 'ip-v4[:端口',
js /^((\d|[1-9\d|1\d\d|2[0-4\d|25[0-5)\.)3}(\d|[1-9\d|1\d\d|2[0-4\d|25[0-5)(?::(?:[0-9|[1-9[0-91,3}|[1-5[0-94}|6[0-4[0-93}|65[0-4[0-92}|655[0-2[0-9|6553[0-5))?$/
示例:'172.16.0.0', '172.16.0.0:8080', '127.0.0.0', '127.0.0.0:998'
# 'ip-v6[:端口',
js /^(?:(?:(?:[0-9A-Fa-f1,4}:)7}[0-9A-Fa-f1,4})|(([0-9A-Fa-f1,4}:)6}:[0-9A-Fa-f1,4})|(([0-9A-Fa-f1,4}:)5}:([0-9A-Fa-f1,4}:)?[0-9A-Fa-f1,4})|(([0-9A-Fa-f1,4}:)4}:([0-9A-Fa-f1,4}:)0,2}[0-9A-Fa-f1,4})|(([0-9A-Fa-f1,4}:)3}:([0-9A-Fa-f1,4}:)0,3}[0-9A-Fa-f1,4})|(([0-9A-Fa-f1,4}:)2}:([0-9A-Fa-f1,4}:)0,4}[0-9A-Fa-f1,4})|(([0-9A-Fa-f1,4}:)6}((\b((25[0-5)|(1\d2})|(2[0-4\d)|(\d1,2}))\b)\.)3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Fa-f1,4}:)0,5}[0-9A-Fa-f1,4})|(::([0-9A-Fa-f1,4}:)0,6}[0-9A-Fa-f1,4})|(([0-9A-Fa-f1,4}:)1,7}:))\(?::(?:[0-9|[1-9[0-91,3}|[1-5[0-94}|6[0-4[0-93}|65[0-4[0-92}|655[0-2[0-9|6553[0-5))?$/i
,
示例:'2031:0000:130f:0000:0000:09c0:876a:130b', '[2031:0000:130f:0000:0000:09c0:876a:130b:8080'
# 时间相关
# '12 小时制时间(hh:mm:ss)',
js /^(?:1[0-2|0?[1-9):[0-5\d:[0-5\d$/
示例:
'11:34:55','23:34:55'
# '24 小时制时间(HH:mm:ss)',
js /^(?:[01\d|2[0-3):[0-5\d:[0-5\d$/
示例:'23:34:55'
# 'date(日期)',
js /^\d1,4}(-)(1[0-2|0?[1-9)\1(0?[1-9|[1-2\d|30|31)$/
示例:'1990-12-12', '1-1-1','0000-1-1',
,'2020-00-01'
# 中文&字母&数字相关
# '中文姓名',
js /^(?:[\u4e00-\u9fa5·2,16})$/
示例:'葛二蛋', '凯文·杜兰特', '德克·维尔纳·诺维茨基'
# '英文姓名',
js /(^[a-zA-Z[a-zA-Z\s0,20}[a-zA-Z$)/
示例:'James', 'Kevin Wayne Durant', 'Dirk Nowitzki'
# '中文/汉字',
/^(?:[\u3400-\u4DB5\u4E00-\u9FEA\uFA0E\uFA0F\uFA11\uFA13\uFA14\uFA1F\uFA21\uFA23\uFA24\uFA27-\uFA29]|[\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0])+$/
示例:'正则', '前端'
# '英文字母',
js /^[a-zA-Z+$/
示例:'Russel'
# '中文和数字',
/^((?:[\u3400-\u4DB5\u4E00-\u9FEA\uFA0E\uFA0F\uFA11\uFA13\uFA14\uFA1F\uFA21\uFA23\uFA24\uFA27-\uFA29]|[\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0])|(\d))+$/
示例:'哈哈哈', '你好6啊'
# '数字和英文字母组成,并且同时含有数字和英文字母',
js /^(?=.*[a-zA-Z)(?=.*\d).+$/
示例:'我a我1我', 'a对1'
# '小写英文字母组成',
js /^[a-z+$/
示例:'russel'
# '大写英文字母',
js /^[A-Z+$/
示例:'ABC', 'KD'
# '不能包含字母',
js /^[^A-Za-z*$/
示例:'你好6啊', '@¥()!'
# '匹配连续重复的字符',
js /(.)\1+/
示例:'我我我', '112233', '11234'
# 车牌相关
# '火车车次'
/^[GCDZTSPKXLY1-9\d1,4}$/
示例:'G1868', 'D102', 'D9', 'Z5', 'Z24', 'Z17'
# '车牌号(新能源)',
js /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领[A-HJ-NP-Z(?:((\d5}[A-HJK)|([A-HJK[A-HJ-NP-Z0-9[0-94}))|[A-HJ-NP-Z0-94}[A-HJ-NP-Z0-9挂学警港澳)$/
示例:'京AD92035', '甘G23459F', '京AA92035',
# '车牌号(非新能源)',
js /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领[A-HJ-NP-Z[A-HJ-NP-Z0-94}[A-HJ-NP-Z0-9挂学警港澳$/
示例:'京A00599', '黑D23908'
# '车牌号(新能源+非新能源)',
js /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领[A-HJ-NP-Z[A-HJ-NP-Z0-94,5}[A-HJ-NP-Z0-9挂学警港澳$/
示例:'京A12345D', '京A00599', '京AD92035', '甘G23459F', '京AA92035',
,'宁AD1234555555', '浙苏H6F681'
# 其他相关
# '大于等于 0, 小于等于 150, 支持小数位出现 5, 如 145.5, 用于判断考卷分数',
js /^150$|^(?:\d|[1-9\d|1[0-4\d)(?:\.5)?$/
**示例:**150, 100.5
# 'html 注释',
js /^<!--[\s\S*?-->$/
示例:''
# 'md5 格式(32 位)',
js /^([a-f\d32}|[A-F\d32})$/
示例:'21fe181c5bfc16306a6828c1f7b762e8',
# 'GUID/UUID'
js /^[a-f\d4}(?:[a-f\d4}-)4}[a-f\d12}$/i
示例:
'e155518c-ca1b-443c-9be9-fe90fdab7345', '41E3DAF5-6E37-4BCC-9F8E-0D9521E2AA8D', '00000000-0000-0000-0000-000000000000'
# '版本号(version)格式必须为 X.Y.Z',
js /^\d+(?:\.\d+)2}$/
示例:'16.3.10'
# '16 进制颜色',
js /^#?([a-fA-F0-96}|[a-fA-F0-93})$/
示例:'#f00', '#F90', '#000', '#fe9de8'
# 'java 包名',
js /^([a-zA-Z_\w*)+([.[a-zA-Z_\w*)+$/
示例:'com.bbb.name'
# 'html 标签(宽松匹配)',
js /<(\w+)[^>*>(.*?<\/\1>)?/
示例:'
'