您的位置:首页 > Web前端 > HTML5

html5实现 input必须为手机号且非空的验证方法

2016-05-03 17:06 726 查看
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>文哥讨厌IE</title>
<script language="javascript" type="text/javascript">

function checkMobile(str) {
if(str==""){
alert("手机号不能为空!");
}
else{
var re = /^1\d{10}$/                                以1开始后面加10位数字
if (re.test(str)) {
alert("正确");
} else {
alert("手机号格式错误!");
}
}
}
</script>
</head>
<body>
<input type="text" id="btn_getNum"/>
<input type="button" value="得到数字" onclick="checkMobile(btn_getNum.value);"/>
</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: