js邮编、手机号、姓名限定

联系电话:<input type="text" name="lxdh" id="lxdh" onblur="checkPhone()" style="width:500px;">
<div id="sjh" style="color:red;display:none">手机号有误!</div>
 联 系 人:<input type="text" name="xm" onblur="uname1()" id="xm" style="width:500px;"><br>
  <div id="lxr" style="color:red;display:none">姓名填写有误!</div>
 
邮政编码:<input type="text" name="yzbm" id="yzbm" onblur="ischeck()"  style="width:500px;">
<div id="yzbm1" style="color:red;display:none">邮政编码有误!</div>



function ischeck(){//验证邮政编码
    var yb = document.getElementById('yzbm').value;
    if(!(/^[0-8][0-7]\d{4}$/.test(yb))){ 
        document.getElementById("yzbm1").style.display="block"; 
         // alert("邮政编码格式不符合要求");
        return false; 
    } document.getElementById("yzbm1").style.display="none";  
    return true; 
}
function uname1(){
          var name = $('#xm').val();
    var regName =/^[\u4E00-\u9FA5\uf900-\ufa2d·s]{2,20}$/;  
    if(!regName.test(name)){  
        document.getElementById("lxr").style.display="block"; 
        //alert("姓名格式不符合要求");
        return false;  
     } document.getElementById("lxr").style.display="none"; 
     return true;
            }

function checkPhone(){ //验证手机号
    var phone = document.getElementById('lxdh').value;
    if(!(/^1[3456789]\d{9}$/.test(phone))){ 
        document.getElementById("sjh").style.display="block"; 
         // alert("手机号格式不符合要求");
        return false; 
    } document.getElementById("sjh").style.display="none";  
    return true; 
}

 

posted @ 2020-05-07 10:30  逐梦武威  阅读(257)  评论(0编辑  收藏  举报