Home > Web Front-end > JS Tutorial > body text

js method for email verification of user input

angryTom
Release: 2020-01-14 15:56:11
forward
2669 people have browsed it

js method for email verification of user input

js method for email verification of user input

<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <title>title</title>

</head>

<body>
  <!-- 请您输入邮箱地址:<input type="text" value="" id="email"/> *<br/> -->
  请您输入邮箱地址:<input type="text" value="" id="email" /> *<br />
  <script>
    //如果输入的是邮箱,那么背景颜色为绿色,否则为红色
    //获取文本框,注册失去焦点的事件
    document.getElementById("email").onblur = function () {
      //判断这个文本框中输入的是不是邮箱
      var reg = /^[0-9a-zA-Z_.-]+[@][0-9a-zA-Z_.-]+([.][a-zA-Z]+){1,2}$/;
      if (reg.test(this.value)) {
        this.style.backgroundColor = "green";
      } else {
        this.style.backgroundColor = "red";
      }
    };
  </script>

</body>

</html>
Copy after login

js method for email verification of user input

This article comes from js tutorial column, welcome to learn!

The above is the detailed content of js method for email verification of user input. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!