在网上查了半天,发现好多也是不可行的,最后自己还得看书,看懂了才知道错在哪里. ^([^/x00-/xff]){2,5}$ function chkTxt(sender,chkType){ var rgEx= new RegExp("[^'^,^/"]*"); var strMessage=""; switch(chkType){ case "int": rgEx= /[0-9]/; strMessage="请输入数字"; break case "date": strMessage="请输入正确的日期"; rgEx= /((^((1[8-9]/d{2})|([2-9]/d{3}))([-///._])(10|12|0?[13578])([-///._])(3[01]|[12][0-9]|0?[1-9])$)|(^((1[8-9]/d{2})|([2-9]/d{3}))([-///._])(11|0?[469])([-///._])(30|[12][0-9]|0?[1-9])$)|(^((1[8-9]/d{2})|([2-9]/d{3}))([-///._])(0?2)([-///._])(2[0-8]|1[0-9]|0?[1-9])$)|(^([2468][048]00)([-///._])(0?2)([-///._])(29)$)|(^([3579][26]00)([-///._])(0?2)([-///._])(29)$)|(^([1][89][0][48])([-///._])(0?2)([-///._])(29)$)|(^([2-9][0-9][0][48])([-///._])(0?2)([-///._])(29)$)|(^([1][89][2468][048])([-///._])(0?2)([-///._])(29)$)|(^([2-9][0-9][2468][048])([-///._])(0?2)([-///._])(29)$)|(^([1][89][13579][26])([-///._])(0?2)([-///._])(29)$)|(^([2-9][0-9][13579][26])([-///._])(0?2)([-///._])(29)$))/; break case "email": strMessage="请输入正确的邮箱格式,如abc@126.com"; rgEx=/^([a-z0-9_/.-]+)@([/da-z/.-]+)/.([a-z/.]{2,6})$/ break; case "qq": strMessage="请输入正确的QQ号"; rgEx=/[1-9][0-9]{4,}/ break; case "name": strMessage="请输入2-5个中文字符"; rgEx=/^([^/x00-/xff]){2,5}$/ break; case "notemp": strMessage="不能为空"; rgEx=/^/S+$/; break; }//分支 var lblID=sender.id.replace("txt","").replace("ddl",""); lblID="lbl"+lblID; if(rgEx.exec(sender.value.replace(" ","").replace(" ",""))){ showTip(lblID,1,"填写正确"); return true; } else{ showTip(lblID,2,strMessage); return false; } }//blurTxt