直接上代码
<div class="center_yh hidden_yh" style="width: 475px;margin-bottom: 40px;">
<span style="margin-right: 40px;height: 42px;line-height: 42px;width: 100px;" class="left_yh block_yh tright">手机号:</span>
<input
required oninvalid="setCustomValidity('手机号不能为空')" οninput="setCustomValidity('')"
type="text" name="phone" id="phone" placeholder="建议使用常用的手机" style="border:1px solid #c9c9c9;width: 292px;height: 42px;font-size: 16px;text-indent: 22px;" class="left_yh">
</div>
window.onload = function (){
var phone = document.getElementById('phone');
phone.onblur = function (){
var str = this.value;
if (str != ""){
var reg = /^1[3-9]\d{9}$/;
if (reg.test(str)){
}else {
alert("号码不正确!")
this.value="";
}
console.log(str);
}
}
}