Home > Web Front-end > HTML Tutorial > 大白HELP_html/css_WEB-ITnose

大白HELP_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:15:22
Original
1303 people have browsed it


回复讨论(解决方案)


   
   


   
   手机验证
   
   
       <script> <br /> function aa(obj) <br /> { <br /> obj = document.getElementById("inputContent").value; <br /> var reg = new RegExp("^[0-9]*$"); <br /> <br /> if(obj.length != 11) <br /> { <br /> alert("手机号码长度应该是11位"); <br /> } <br /> else if(!reg.test(obj)) <br /> { <br /> alert("手机号码应该全部是数字"); <br /> } <br /> else if(obj[0]!= "1" || obj[1]!= "3") <br /> { <br /> alert("手机号码应该13开头"); <br /> } <br /> else <br /> { <br /> alert("你填的是正确的手机号码!"); <br /> } <br /> } <br /> </script>
   
手机号码:
   
   

   
   

或者  下面的方法
  function aa(obj)
   {  
      obj = document.getElementById("inputContent").value;
 var reg = new RegExp("^[0-9]*$");
var reg1 = /^13\d{9}$/;  
      if(obj.length != 11)
  {
     alert("手机号码长度应该是11位");
  }
          else if(!reg.test(obj))
  {
     alert("手机号码应该全部是数字");
  }
 // else if(obj[0]!= "1" || obj[1]!= "3")
   else if(!reg1.test(obj))
  {
     alert("手机号码应该13开头");
  }
  else
  {
     alert("你填的是正确的手机号码!");
  }
   }

Related labels:
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