Skip to content

Commit 458abe0

Browse files
committed
更新 any-rule 正则
1 parent ba3e327 commit 458abe0

File tree

1 file changed

+131
-36
lines changed

1 file changed

+131
-36
lines changed

src/views/feature_example/rules.vue

+131-36
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@ const rules = ref([
2727
counterExamples: ['192.168.1.1', 'https://www.jd.com'],
2828
},
2929
{
30-
title: '网址(url,支持端口和"?+参数"和"#+参数)',
31-
rule: /^(((ht|f)tps?):\/\/)?[\w-]+(\.[\w-]+)+([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-])?$/,
32-
examples: ['www.qq.com', 'https://baidu.com', '360.com:8080/vue/#/a=1&b=2'],
30+
// 参考:
31+
// https://baike.baidu.com/item/%E9%A1%B6%E7%BA%A7%E5%9F%9F%E5%90%8D#4_1
32+
// https://baike.baidu.com/item/%E9%A1%B6%E7%BA%A7%E5%9F%9F%E5%90%8D#7
33+
// 也参考谷歌浏览器的地址栏, 如果输入非字母不会被识别为域名
34+
title: '网址(URL)',
35+
rule: /^(((ht|f)tps?):\/\/)?([^!@#$%^&*?.\s-]([^!@#$%^&*?.\s]{0,63}[^!@#$%^&*?.\s])?\.)+[a-z]{2,6}\/?/,
36+
examples: ['www.qq.com', 'https://vuejs.org/v2/api/#v-model', 'www.qq.99', '//www.qq.com', 'www.腾讯.cs', 'ftp://baidu.qq', 'http://baidu.com', 'https://www.amap.com/search?id=BV10060895&city=420111&geoobj=113.207951%7C29.992557%7C115.785782%7C31.204369&query_type=IDQ&query=%E5%85%89%E8%B0%B7%E5%B9%BF%E5%9C%BA(%E5%9C%B0%E9%93%81%E7%AB%99)&zoom=10.15', '360.com:8080/vue/#/a=1&b=2'],
3337
counterExamples: ['....'],
3438
},
3539
{
@@ -60,9 +64,9 @@ const rules = ref([
6064
examples: ['magnet:?xt=urn:btih:40A89A6F4FB1498A98087109D012A9A851FBE0FC'],
6165
},
6266
{
63-
title: '子网掩码',
64-
rule: /^(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(?:\.(?:\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/,
65-
examples: ['255.255.255.0', '255.224.0.0'],
67+
title: '子网掩码(不包含 0.0.0.0)',
68+
rule: /^(254|252|248|240|224|192|128)\.0\.0\.0|255\.(254|252|248|240|224|192|128|0)\.0\.0|255\.255\.(254|252|248|240|224|192|128|0)\.0|255\.255\.255\.(255|254|252|248|240|224|192|128|0)$/,
69+
examples: ['255.255.255.0', '255.255.255.255', '255.240.0.0'],
6670
},
6771
{
6872
title: 'linux"隐藏文件"路径',
@@ -72,7 +76,7 @@ const rules = ref([
7276
{
7377
title: 'linux文件夹路径',
7478
rule: /^\/(?:[^/]+\/)*$/,
75-
examples: ['/usr/ad/dd/', '/', '/root/'],
79+
examples: ['/usr/ad/dd/', '/', '/root/', '/ a a / a / a a /'],
7680
},
7781
{
7882
title: 'linux文件路径',
@@ -101,12 +105,12 @@ const rules = ref([
101105
},
102106
{
103107
title: 'html注释',
104-
rule: /^<!--[\s\S]*?-->$/,
105-
examples: ['<!--<div class="_bubble"></div>-->'],
108+
rule: /<!--[\s\S]*?-->/g,
109+
examples: ['<!--<div class="_bubble"></div>--><div>chenguzhen87</div><div class="_bubble"></div>-->'],
106110
},
107111
{
108112
title: 'md5格式(32位)',
109-
rule: /^([a-f\d]{32}|[A-F\d]{32})$/,
113+
rule: /^[a-fA-F0-9]{32}$/,
110114
examples: ['21fe181c5bfc16306a6828c1f7b762e8'],
111115
},
112116
{
@@ -127,7 +131,7 @@ const rules = ref([
127131
{
128132
title: '图片(image)链接地址(图片格式可按需增删)',
129133
rule: /^https?:\/\/(.+\/)+.+(\.(gif|png|jpg|jpeg|webp|svg|psd|bmp|tif))$/i,
130-
examples: ['https://www.abc.com/logo.png'],
134+
examples: ['https://www.abc.com/logo.png', 'http://www.abc.com/logo.png'],
131135
},
132136
{
133137
title: '24小时制时间(HH:mm:ss)',
@@ -147,14 +151,9 @@ const rules = ref([
147151
},
148152
{
149153
title: '数字/货币金额(支持负数、千分位分隔符)',
150-
rule: /^-?\d+(,\d{3})*(\.\d{1,2})?$/,
154+
rule: /^-?\d{1,3}(,\d{3})*(\.\d{1,2})?$/,
151155
examples: [100, -0.99, 3, 234.32, -1, 900, 235.09, '12,345,678.90'],
152156
},
153-
{
154-
title: '数字/货币金额 (只支持正数、不支持校验千分位分隔符)',
155-
rule: /(?:^[1-9]([0-9]+)?(?:\.[0-9]{1,2})?$)|(?:^(?:0)$)|(?:^[0-9]\.[0-9](?:[0-9])?$)/,
156-
examples: [0.99, 8.99, 666],
157-
},
158157
{
159158
title: '银行卡号(10到30位, 覆盖对公/私账户, 参考[微信支付](https://pay.weixin.qq.com/wiki/doc/api/xiaowei.php?chapter=22_1))',
160159
rule: /^[1-9]\d{9,29}$/,
@@ -172,8 +171,8 @@ const rules = ref([
172171
},
173172
{
174173
title: '车牌号(新能源)',
175-
rule: /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z](?:((\d{5}[A-HJK])|([A-HJK][A-HJ-NP-Z0-9][0-9]{4}))|[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳])$/,
176-
examples: ['京AD92035', '甘G23459F', '京AA92035'],
174+
rule: /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-HJ-NP-Z](([DF]((?![IO])[a-zA-Z0-9](?![IO]))[0-9]{4})|([0-9]{5}[DF]))$/,
175+
examples: ['京AD92035', '甘G23459F', '京A19203D'],
177176
},
178177
{
179178
title: '车牌号(非新能源)',
@@ -187,9 +186,9 @@ const rules = ref([
187186
counterExamples: ['宁AD1234555555', '浙苏H6F681'],
188187
},
189188
{
190-
title: '手机号(mobile phone)中国(严谨), 根据工信部2019年最新公布的手机号段',
191-
rule: /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[189]))\d{8}$/,
192-
examples: ['008618311006933', '+8617888829981', '19119255642'],
189+
title: '手机号(mobile phone)中国(严谨), 根据工信部最新公布的手机号段',
190+
rule: /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[01256789]))\d{8}$/,
191+
examples: ['008618311006933', '+8617888829981', '19119255642', '19519255642'],
193192
},
194193
{
195194
title: '手机号(mobile phone)中国(宽松), 只要是13,14,15,16,17,18,19开头即可',
@@ -202,15 +201,36 @@ const rules = ref([
202201
examples: ['008618311006933', '+8617888829981', '19119255642'],
203202
},
204203
{
205-
title: 'date(日期)',
204+
title: '日期(宽松)',
206205
rule: /^\d{1,4}(-)(1[0-2]|0?[1-9])\1(0?[1-9]|[1-2]\d|30|31)$/,
207206
examples: ['1990-12-12', '1-1-1', '0000-1-1'],
208207
counterExamples: ['2020-00-01'],
209208
},
209+
210+
{
211+
title: '日期(严谨, 支持闰年判断)',
212+
rule: /^(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)$/,
213+
examples: ['1990-12-12', '2000-02-29'],
214+
counterExamples: ['2021-02-29'],
215+
},
216+
217+
{
218+
title: '中国省',
219+
rule: /^浙江|上海|北京|天津|重庆|黑龙江|吉林|辽宁|内蒙古|河北|新疆|甘肃|青海|陕西|宁夏|河南|山东|山西|安徽|湖北|湖南|江苏|四川|贵州|云南|广西|西藏|江西|广东|福建|台湾|海南|香港|澳门$/,
220+
examples: ['浙江', '台湾'],
221+
counterExamples: ['哈尔滨'],
222+
},
223+
224+
{
225+
title: '可以被moment转化成功的时间 YYYYMMDD HH:mm:ss',
226+
rule: /^\d{4}([/:-\S])(1[0-2]|0?[1-9])\1(0?[1-9]|[1-2]\d|30|31) (?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d$/,
227+
examples: ['2020/01/01 23:59:59', '2020-01-01 00:00:00', '20200101 11:11:11'],
228+
counterExamples: ['2020/00/01 23:59:59', '2020-01/01 23:59:59', '2020-01-01 23:59:61', '2020-01-0100:00:00'],
229+
},
210230
{
211231
title: 'email(邮箱)',
212232
rule: /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,
213-
233+
examples: ['[email protected]', '[email protected]', '汉字@qq.com'],
214234
},
215235
216236
{
@@ -231,8 +251,8 @@ const rules = ref([
231251
},
232252
{
233253
title: '身份证号, 支持1/2代(15位/18位数字)',
234-
rule: /(^\d{8}(0\d|10|11|12)([0-2]\d|30|31)\d{3}$)|(^\d{6}(18|19|20)\d{2}(0[1-9]|10|11|12)([0-2]\d|30|31)\d{3}(\d|X|x)$)/,
235-
examples: ['622223199912051311'],
254+
rule: /^\d{6}((((((19|20)\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|(((19|20)\d{2})(0[13578]|1[02])31)|((19|20)\d{2})02(0[1-9]|1\d|2[0-8])|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))0229))\d{3})|((((\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|((\d{2})(0[13578]|1[02])31)|((\d{2})02(0[1-9]|1\d|2[0-8]))|(([13579][26]|[2468][048]|0[048])0229))\d{2}))(\d|X|x)$/,
255+
examples: ['622223199912051311', '12345619991205131x', '123456991010193'],
236256
},
237257
{
238258
title: '护照(包含香港、澳门)',
@@ -251,20 +271,27 @@ const rules = ref([
251271
examples: ['正则', '前端'],
252272
},
253273
{
254-
title: '小数',
255-
rule: /^\d+\.\d+$/,
256-
examples: ['0.0', '0.09'],
274+
title: '小数(支持科学计数)',
275+
rule: /^[+-]?(\d+([.]\d*)?([eE][+-]?\d+)?|[.]\d+([eE][+-]?\d+)?)$/,
276+
examples: ['0.0', '0.09', '4E+4'],
257277
},
258278
{
259-
title: '数字',
260-
rule: /^\d{1,}$/,
279+
title: '只包含数字',
280+
rule: /^\d+$/,
261281
examples: [12345678],
262282
},
263283
{
264284
title: 'html标签(宽松匹配)',
265285
rule: /<(\w+)[^>]*>(.*?<\/\1>)?/,
266286
examples: ['<div id="app"> 2333 </div>', '<input type="text">', '<br>'],
267287
},
288+
289+
{
290+
title: '匹配中文汉字和中文标点',
291+
rule: /[\u4E00-\u9FA5|\u3002|\uFF1F|\uFF01|\uFF0C|\u3001|\uFF1B|\uFF1A|\u201C|\u201D|\u2018|\u2019|\uFF08|\uFF09|\u300A|\u300B|\u3008|\u3009|\u3010|\u3011|\u300E|\u300F|\u300C|\u300D|\uFE43|\uFE44|\u3014|\u3015|\u2026|\u2014|\uFF5E|\uFE4F|\uFFE5]/,
292+
examples: ['匹配中文汉字以及中文标点符号 。 ? ! , 、 ; : “ ” ‘ \' ( ) 《 》 〈 〉 【 】 『 』 「 」 ﹃ ﹄ 〔 〕 … — ~ ﹏ ¥'],
293+
},
294+
268295
{
269296
title: 'qq号格式正确',
270297
rule: /^[1-9][0-9]{4,10}$/,
@@ -297,7 +324,7 @@ const rules = ref([
297324
},
298325
{
299326
title: '用户名校验,4到16位(字母,数字,下划线,减号)',
300-
rule: /^[a-zA-Z0-9_-]{4,16}$/,
327+
rule: /^[\w-]{4,16}$/,
301328
examples: ['xiaohua_qq'],
302329
},
303330
{
@@ -307,8 +334,8 @@ const rules = ref([
307334
},
308335
{
309336
title: '16进制颜色',
310-
rule: /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/,
311-
examples: ['#f00', '#F90', '#000', '#fe9de8'],
337+
rule: /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3}|[a-fA-F0-9]{8}|[a-fA-F0-9]{4})$/,
338+
examples: ['#f00', '#F90', '#000', '#fe9de8', '#f8f8f8ff', '#f003'],
312339
},
313340
{
314341
title: '微信号(wx),6至20位,以字母开头,字母,数字,减号,下划线',
@@ -337,7 +364,7 @@ const rules = ref([
337364
},
338365
{
339366
title: 'mac地址',
340-
rule: /^((([a-f0-9]{2}:){5})|(([a-f0-9]{2}-){5}))[a-f0-9]{2}$/i,
367+
rule: /^(([a-f0-9][0,2,4,6,8,a,c,e]:([a-f0-9]{2}:){4})|([a-f0-9][0,2,4,6,8,a,c,e]-([a-f0-9]{2}-){4}))[a-f0-9]{2}$/i,
341368
examples: ['38:f9:d3:4b:f5:51', '00-0C-29-CA-E4-66'],
342369
},
343370
{
@@ -356,15 +383,83 @@ const rules = ref([
356383
examples: ['K034169(1)'],
357384
},
358385
{
386+
// 参考:
387+
// https://baike.baidu.com/item/%E6%BE%B3%E9%97%A8%E5%B1%85%E6%B0%91%E8%BA%AB%E4%BB%BD%E8%AF%81/12509098?fr=aladdin#5
359388
title: '澳门身份证 ',
360-
rule: /^[1|5|7]\d{6}[(\d)]{3}$/,
389+
rule: /^[1|5|7]\d{6}\(\d\)$/,
361390
examples: ['5686611(1)'],
362391
},
363392
{
364393
title: '台湾身份证 ',
365394
rule: /^[a-zA-Z][0-9]{9}$/,
366395
examples: ['U193683453'],
367396
},
397+
{
398+
title: '大写字母,小写字母,数字,特殊符号 `@#$%^&*`~()-+=` 中任意3项密码',
399+
rule: /^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\W_!@#$%^&*`~()-+=]+$)(?![0-9\W_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9\W_!@#$%^&*`~()-+=]/,
400+
examples: ['a1@', 'A1@', 'Aa@'],
401+
},
402+
{
403+
title: 'ASCII码表中的全部的特殊字符',
404+
rule: /[\x21-\x2F\x3A-\x40\x5B-\x60\x7B-\x7E]+/,
405+
examples: ['[', '.', '^', '&3%'],
406+
},
407+
{
408+
title: '正整数,不包含0',
409+
rule: /^\+?[1-9]\d*$/,
410+
examples: [1231],
411+
},
412+
{
413+
title: '负整数,不包含0',
414+
rule: /^-[1-9]\d*$/,
415+
examples: [-1231],
416+
},
417+
{
418+
title: '整数',
419+
rule: /^(?:0|(?:-?[1-9]\d*))$/,
420+
examples: [-1231, 123, 0],
421+
counterExamples: ['01'],
422+
},
423+
{
424+
title: '浮点数',
425+
rule: /^(-?[1-9]\d*\.\d+|-?0\.\d*[1-9]\d*|0\.0+)$/,
426+
examples: ['1.23', '-1.01', '0.00'],
427+
// allow "1.23", allow "-0.1", allow "0.00", ban "-0.00", ban "2.", allow "2.0"
428+
},
429+
{
430+
title: '浮点数(严格)',
431+
rule: /^(-?[1-9]\d*\.\d+|-?0\.\d*[1-9])$/,
432+
examples: ['1.23', '-1.01'],
433+
// allow "1.23", allow "-0.1", ban "2.", ban "2.0"
434+
},
435+
{
436+
title: 'email(支持中文邮箱)',
437+
rule: /^[A-Za-z0-9\u4E00-\u9FA5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,
438+
examples: ['[email protected]', '[email protected]', '啦啦啦@126.com'],
439+
},
440+
441+
{
442+
title: '域名(非网址, 不包含协议)',
443+
rule: /^([0-9a-zA-Z-]{1,}\.)+([a-zA-Z]{2,})$/,
444+
examples: ['www.baidu.com',
445+
'baidu.com',
446+
'baidu.com.cn',
447+
'api.baidu.com',
448+
'nodejs.org',
449+
'nodejs.cn'],
450+
counterExamples: ['http://baidu.com', 'https://baidu.com', 'www.百度.com'],
451+
},
452+
453+
{
454+
title: '军官/士兵证',
455+
rule: /^[\u4E00-\u9FA5](字第)([0-9a-zA-Z]{4,8})(号?)$/,
456+
examples: ['军字第2001988号', '士字第P011816X号'],
457+
},
458+
{
459+
title: '户口薄',
460+
rule: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/,
461+
examples: ['441421999707223115'],
462+
},
368463
])
369464
370465
const dialog = ref({

0 commit comments

Comments
 (0)