input验证是否为有效手机号码,亲测可用

时间:2021-06-05 09:22:13

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="decription" content="This is an HTML5 example">
    <meta name="keywords" content="HTML5,CSS3,Javascript">
	<title>HTML5</title>
</head>
<body>
<input type="text" id="mytest" >
<button onclick="test_()">submit</button>
<script type="text/javascript">
	function test_(){
		var theinput=document.getElementById("mytest").value;
		  var p1=/^(13[0-9]\d{8}|15[0-35-9]\d{8}|18[0-9]\{8}|14[57]\d{8})$/;
		 //(p1.test(theinput));
			if(p1.test(theinput)==false) {		  
		alert('请填写正确电话号码!!');		  
		document.getElementById("mytest").value="";
	}
	else alert("succeess");
	}
</script>
</body>
</html>
网上很多不能用,,所以自己写了个