7.案例.html 842 B

12345678910111213141516171819202122232425262728
  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.手机号脱敏 13748576543 => 137****6543
  11. // const str = '13748576543';
  12. // const reg = /^(1[3-9]\d)\d{4}(\d{4})$/;
  13. // console.log(str.replace(reg,'$1****$2'))
  14. // 2.密码匹配 (6-16字母,数字,下划线)
  15. // const reg = /^\w{6,16}$/
  16. // // const reg = /^[a-zA-Z0-9_]{6,16}$/
  17. // console.log(reg.test("hello12345"))
  18. // 3.匹配16进制颜色
  19. // const reg = /^#([0-9a-fA-F]{6})|([0-9a-fA-F]{3})$/
  20. // console.log(reg.test("#ff0000"))
  21. // console.log(reg.test("#ff0"))
  22. // 匹配24小时时间 23:59
  23. </script>
  24. </body>
  25. </html>