06.邮件的正则.html 967 B

1234567891011121314151617181920212223242526272829303132
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <script>
  9. /*
  10. 电子邮件
  11. hello@abc.com.cn(hello.li@abc.com.cn)
  12. 规则:
  13. 任意字母数字下划线 .任意字母数字下划线 @ 任意字母数字 . 任意字母(2-5位) . 任意字母(2-5位)
  14. \w{3,} (\. \w+)* @ [A-z0-9]+ (\. [A-z]{2,5}){1,2}
  15. */
  16. var emailReg = /^\w{3,}(\.\w+)*@[A-z0-9]+(\.[A-z]{2,5}){1,2}$/;
  17. // var email = "abc@bcd.com.123";//false
  18. // var email = "abc@bcd.com";//true
  19. // var email = "123abc.hello@bcd.com";//true
  20. var email = "@abc.hello@bcd.com";//false
  21. console.log(emailReg.test(email));
  22. </script>
  23. </head>
  24. <body>
  25. </body>
  26. </html>