e 1 жил өмнө
parent
commit
4fc65b4193

+ 20 - 0
正则/晚课/7.案例.html

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