|
@@ -10,9 +10,24 @@
|
|
|
<body>
|
|
|
<script>
|
|
|
// 1.手机号脱敏 13789430987 => 137****0987
|
|
|
+ const str = '13789430987';
|
|
|
+ const reg = /^(1\d{2})\d{4}(\d{4})$/;
|
|
|
+ console.log(str.replace(reg,'$1****$2'));
|
|
|
// 2.密码匹配 (6-16字母、数字、下划线)
|
|
|
+ const str1 = 'hello_123456';
|
|
|
+ const reg1 = /^\w{6,16}$/;
|
|
|
// 3.匹配16进制颜色 #ff0000 #0f0
|
|
|
+ const str2 = '#ff0000';
|
|
|
+ const str3 = '#0f0';
|
|
|
+ const reg3 = /^#([a-fA-f0-9]{6})|#([a-fA-f0-9]{3})$/
|
|
|
+ console.log(reg3.test(str2));
|
|
|
+ console.log(reg3.test(str3));
|
|
|
// 4.匹配24小时时间 23:59 20:12 08:35 18:22
|
|
|
+ const reg4 = /^([0-1][0-9])|([2][0-3]):[0-5][0-9]$/;
|
|
|
+ console.log(reg4.test("23:59"));
|
|
|
+ console.log(reg4.test("20:12"));
|
|
|
+ console.log(reg4.test("08:35"));
|
|
|
+ console.log(reg4.test("18:22"));
|
|
|
</script>
|
|
|
</body>
|
|
|
|