JS检查是否为数字 封装函数

/* numberCheck(pId,pStatus)
 *检查是否为数字
 * 两个参数 1:dom结构的ID  2:true为小数 fale不是小数
 */  
function numberCheck(pId,pStatus){
   var tValue = document.getElementById(pId).value;
   var tFoamt = "";
   if(pStatus){
      tFoamt = /^\d+(\.\d+)?$/.test(tValue);
   }
   else{
      tFoamt = /^[0-9]*$/g.test(tValue);
   }
   if(tValue != ""){
      if(tFoamt){//輸入格式符合
         return true;
      }
      else{//輸入格式不符
         alert("輸入格式不符 !");
         document.getElementById(pId).value = "";
         return false;
      }
   }
}

//更多前后端封装方法加QQ473190078随时免费回答(不要问我为什么人好没办法)   

猜你喜欢

转载自blog.csdn.net/qq_34527689/article/details/87790780