$(function(){ $("input").blur(function(){ if(new RegExp("[`~!@#$^&*()=|{}';'.<>?~!@#¥……&*()——|{}【】‘;”“'。,、?%+_]").test(this.value)){ this.value= this.value.replace(/[^\u4e00-\u9fa5\w]/g,''); } }) //海关代码校验 $("#mainPort").blur(function(){ if(this.value.length>4 || this.value.length<4){ alert("请输入4位海关代码"); }else{ Number(this.value) if(isNaN(Number(this.value))){ alert("请输入纯数字"); } } }) //数字和小数校验 $(".numberCheck").keyup(function(){ this.value=this.value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,''); }) //数据类型校验 $(".operationType").blur(function(){ if(this.value.length>2){ layer.alert("至多2位数据"); } }) //校验联系方式 /*$(".phone").blur(function(){ var reg = /^[1][3,4,5,7,8][0-9]{9}$/; var myreg = /^0\d{2,3}-?\d{7,8}$/g; if(this.value.length===12|this.value.length===13){ if(!myreg.test(this.value)){ alert("不是有效的电话号码") } }else if(this.value.length===11){ if(!reg.test(this.value)){ alert("不是有效的手机号码") } }else{ alert("请输入正确的联系方式") } })*/ })