1. 邮箱验证

  1. <input type="text" placeholder="请输入邮箱" id="email">
  2. <script>
  3. var email = document.getElementById("email");
  4. email.onkeyup = function(event){
  5. if(event.keyCode == 13){
  6. var value = this.value.trim();
  7. var reg = /^[\w]+@[0-9a-z]+\.[a-z]+$/;
  8. console.log(reg.test(value));
  9. }
  10. }
  11. /*邮箱的正则
  12. 395775347@qq.com
  13. 395775347@163.com
  14. cheng_benchao@sina.com
  15. chengg@gmail.com
  16. fdfdj@xx.net
  17. */
  18. /*
  19. [\w]+@[0-9a-z]+\.[a-z]+
  20. */
  21. </script>

2. 密码验证

  1. <input type="text" placeholder="请输入密码" id="email">
  2. <script>
  3. var email = document.getElementById("email");
  4. email.onkeyup = function(event){
  5. if(event.keyCode == 13){
  6. var value = this.value.trim();
  7. var reg = /^[a-zA-z]+\d{5,}$/
  8. console.log(reg.test(value))
  9. }
  10. }
  11. /* 请输入6位数密码
  12. 银行密码
  13. var reg = /^\d{6}$/
  14. */
  15. /*
  16. cheng12345 --true
  17. cheng123 --false
  18. 账户密码
  19. 以为字母开头,后面是数字,数字至少包含5位
  20. var reg = /^[a-zA-z]+\d{5,}$/
  21. */
  22. </script>

3. 用户名验证

  1. <input type="text" placeholder="请输入用户名" id="email">
  2. <script>
  3. var email = document.getElementById("email");
  4. email.onkeyup = function(event){
  5. if(event.keyCode == 13){
  6. var value = this.value.trim();
  7. var reg = /^[a-zA-Z]{1,8}$/
  8. console.log(reg.test(value))
  9. }
  10. }
  11. /*
  12. 用户名只能是字母,大小不限,不能超过8个字符
  13. var reg = /^[a-zA-Z]{1,8}$/
  14. */
  15. /*
  16. 1.电话号码验证
  17. 2.验证码验证(4)
  18. 3.密码验证
  19. 4.邮箱验证
  20. 5.用户名验证
  21. */
  22. </script>