<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
手机号码<input type="text" id="phone">
<span id="cont" style="color: ;"></span>
<script>
phone.οnblur=function(){
// 获取输入框的值
var str=phone.value
console.log(str);
// 正则验证
var p=/^1[3-9]\d{9}$/
var test=p.test(str)
console.log(test);
if(test){
cont.innerHTML='格式正确'
cont.style.color='green'
}else{
cont.innerHTML='格式错误'
cont.style.color='red'
}
}
</script>
</body>
</html>
正则验证:手机号码验证
最新推荐文章于 2024-03-21 15:47:05 发布