|
@@ -8,9 +8,29 @@
|
|
|
<body>
|
|
|
<script>
|
|
|
// 1.手机号脱敏 13684739503 => 136****9503
|
|
|
+ const str = '13684739503';
|
|
|
+ const reg = /^(1\d{2})(\d{4})(\d{4})$/
|
|
|
+ console.log(reg.test(str));
|
|
|
+ console.log(str.replace(reg,'$1****$3'))
|
|
|
// 2.密码匹配 (6-16字母数字下划线)
|
|
|
+ const str1 ='hi58748_87y';
|
|
|
+ const reg1 = /^\w{6,16}$/
|
|
|
+ console.log(reg1.test(str1));
|
|
|
// 3.匹配16进制颜色 #ff0000 #ff0
|
|
|
+ const str2 = '#ff00ff';
|
|
|
+ const reg2 = /^#([a-fA-F0-9]{6})|([a-fA-F0-9]{3})$/
|
|
|
+ console.log(reg2.test(str2));
|
|
|
// 4.匹配24小时时间 23:59 20:09 08:08 18:18
|
|
|
+ const reg3 = /^([0-1][0-9])|([2][0-3]):[0-5][0-9]$/;
|
|
|
+ console.log(reg3.test("23:59"))
|
|
|
+ console.log(reg3.test("20:09"))
|
|
|
+ console.log(reg3.test("08:08"))
|
|
|
+ console.log(reg3.test("18:18"))
|
|
|
+ /**
|
|
|
+ * 1.any-rule
|
|
|
+ * 2/https://regexper.com/ 功能可视化表达式
|
|
|
+ */
|
|
|
+
|
|
|
</script>
|
|
|
</body>
|
|
|
</html>
|