验证手机号是否符合标准
var partten = /^1[3,5,7,8]\d{9}$/; if(partten.test(thisArr)){//判断是否符合手机号码格式 //标准 }else{ //不标准 }
限制输入只能英文或数字
//允许输入数字点,replace(/[^\w\.\/]/ig,'') //限制只能数字 replace(/\D/g,'') onkeyup="this.value=this.value.replace(/[^\w\/]/ig,'');this.value=this.value.toUpperCase()" onafterpaste="this.value=this.value.replace(/[^\w\/]/ig,'');this.value=this.value.toUpperCase()" onblur="this.value=this.value.replace(/[^\w\/]/ig,'');this.value=this.value.toUpperCase()"
验证标准数字:
function num(obj){ obj.value = obj.value.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符 obj.value = obj.value.replace(/^\./g,""); //验证第一个字符是数字 obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个, 清除多余的 obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$","."); //obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); //只能输入两个小数 }
限制自动过滤空格:
<input name="zc_code" type="text" value="" onblur="this.value=this.value.replace(/\s+/g,'')" onkeyup="this.value=this.value.replace(/\s+/g,'')" onafterpaste="this.value=this.value.replace(/\s+/g,'')" />
日期控件:
<input name="date1" type="text" onkeyup="this.value=this.value.replace(/\D/g,'');" onafterpaste="this.value=this.value.replace(/\D/g,'')" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd',skin:'twoer'})" readonly="true" />
限制只能输入金额数字:
<input name="feiyong" type="text" value="" onkeyup="this.value=this.value.replace(/[^\w\.\/]/ig,'');" onafterpaste="this.value=this.value.replace(/[^\w\.\/]/ig,'');" onblur="this.value=this.value.replace(/[^\w\.\/]/ig,'');"/>
判断数字与日期大小:
if (date1!='' && date2!='' && date1>date2){ alert_go('送修时间与报修时间,冲突!','alert','','error','') return false }else if (feiyong!='' && (isNaN(feiyong) || feiyong<0)){ alert_go('维修费用金额,错误!','alert','','error','') return false }