Home > Web Front-end > JS Tutorial > Implement verification method of email format in js

Implement verification method of email format in js

高洛峰
Release: 2016-12-09 11:48:49
Original
1929 people have browsed it

As shown below:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>在此处插入标题</title>
<script type="text/javascript">
//判断用户输入的电子邮箱格式是否正确
function checkEmail(){
  var myforms=document.forms;
  var myemail=myforms[0].email.value;
  var myReg=/^[a-zA-Z0-9_-]+@([a-zA-Z0-9]+\.)+(com|cn|net|org)$/;
 
  if(myReg.test(myemail)){
    return true;
  }else{
    myspan.innerText="邮箱格式不对!";
    return false;
}
}
 
</script>
</head>
<body>
  <form action="#">
    <table>
    <tr><td>邮箱:<input type="text" id=email></td><td><span id=myspan style="text-size:18pt;color:red;"></span></td></tr>
    <tr><td><input type="submit" value="提交" onclick="return checkEmail()"/></td><td></td></tr>
    </table>
  </form>
 
 
</body>
</html>
Copy after login


Related labels:
js
source:php.cn
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