10
0

7.案例.html 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <script>
  10. // 1.手机号脱敏 13782748934 => 137****8934
  11. const str1 = '13782748934';
  12. const reg6 =/^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|10|11|12)(?:0[1-9]|[1-2]\d|30|31)\d{3}[\dXx]$/
  13. const reg1 = /^(1[3-9]{1}\d{1})(\d{4})(\d{4})$/;
  14. console.log(str1.replace(reg1,'$1****$3'))
  15. // 2.密码匹配 (6-16字母、数字、下划线)
  16. const str2 = 'helloworld123_';
  17. const reg2 = /^\w{6,16}$/;
  18. const reg5 =/^\S*(?=\S{6,})(?=\S*\d)(?=\S*[A-Z])(?=\S*[a-z])(?=\S*[!@#$%^&*? ])\S*$/;
  19. console.log(reg2.test(str2));
  20. // 3.匹配16进制颜色(#ff0000 #0f0)
  21. const str3 = '#ff00ff';
  22. const reg3 = /^#([0-9a-fA-F]{3})|([0-9a-fA-F]{6})$/;
  23. console.log(reg3.test(str3));
  24. // 4.匹配24小时时间 23:59 18:22 08:35 20:12
  25. const str4 = "24:12";
  26. const reg4 = /^(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d$/
  27. // const reg4 = /^[0-1][0-9]|2[0-3]:[0-5][0-9]$/;
  28. console.log(reg4.test(str4));
  29. </script>
  30. </body>
  31. </html>