|
@@ -1,19 +1,39 @@
|
|
|
<!DOCTYPE html>
|
|
<!DOCTYPE html>
|
|
|
<html lang="en">
|
|
<html lang="en">
|
|
|
|
|
+
|
|
|
<head>
|
|
<head>
|
|
|
<meta charset="UTF-8">
|
|
<meta charset="UTF-8">
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
<title>Document</title>
|
|
<title>Document</title>
|
|
|
</head>
|
|
</head>
|
|
|
|
|
+
|
|
|
<body>
|
|
<body>
|
|
|
<script>
|
|
<script>
|
|
|
// 1.手机号脱敏 13789430987 => 137****0987
|
|
// 1.手机号脱敏 13789430987 => 137****0987
|
|
|
-
|
|
|
|
|
|
|
+ const str1 = '13789430987';
|
|
|
|
|
+ const reg1 = /^(1\d{2})(\d{4})(\d{4})$/;
|
|
|
|
|
+ console.log(str1.replace(reg1, '$1****$3'));
|
|
|
// 2.密码匹配 (6-16字母、数字、下划线)
|
|
// 2.密码匹配 (6-16字母、数字、下划线)
|
|
|
-
|
|
|
|
|
|
|
+ const str2 = 'hello123456';
|
|
|
|
|
+ const reg2 = /^\w{6,16}$/;
|
|
|
|
|
+ console.log(reg2.test(str2));
|
|
|
// 3.匹配16进制颜色 #ff0000 #0f0
|
|
// 3.匹配16进制颜色 #ff0000 #0f0
|
|
|
-
|
|
|
|
|
|
|
+ const str3 = '#ff0000';
|
|
|
|
|
+ const str4 = '#0f0';
|
|
|
|
|
+ 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
|
|
// 4.匹配24小时时间 23:59 20:12 08:35 18:22
|
|
|
|
|
+ const str5 = '23:59';
|
|
|
|
|
+ const str6 = '20:12';
|
|
|
|
|
+ const str7 = '08:35';
|
|
|
|
|
+ const str8 = '18:22';
|
|
|
|
|
+ const reg4 = /^([0-1][0-9])|([2][0-3]):[0-5][0-9]$/;
|
|
|
|
|
+ console.log(reg4.test(str5));
|
|
|
|
|
+ console.log(reg4.test(str6));
|
|
|
|
|
+ console.log(reg4.test(str7));
|
|
|
|
|
+ console.log(reg4.test(str8));
|
|
|
</script>
|
|
</script>
|
|
|
</body>
|
|
</body>
|
|
|
|
|
+
|
|
|
</html>
|
|
</html>
|