js中防止输入为空,或者为字母

   

function checkNum(){
     
    var num1=document.getElementById("num1").value;
    var num2=document.getElementById("num2").value;
    if(num1 == "" || num2== "" ){
        window.alert("not null");
        return false;
    }
    
  //不能带gi
    var reg=/^[1-9]\d*(\.[0-9]+)?$|^0$/i;
    if(!reg.test(num1) || !reg.test(num2)){
        window.alert("input numbers only");
        return false;
    }
}

 

posted on 2017-09-18 17:17  SunnyCx  阅读(305)  评论(0编辑  收藏  举报

导航