js前台数据校验
1.腳本
Validator = {exp:{numWord:/^[A-Za-z0-9]+$/, //數字或字母numWordM:/^[\-]*[A-Za-z0-9]+$/, //數字或字母可為負數letter:/^[A-Za-z]+$/, //字母chinese:/^[\u4E00-\u9FA5\uF900-\uFA2D]+$/,numberReg:/^[0-9]+$/,//數字格式 只能是0到9的數字 eg:92wordReg:/^(\w|[\u4E00-\u9FA5])*$/,//中文,字母,數字wordRegAnd_:/^(\w|[\u4E00-\u9FA5\-])*$/,//中文,字母,數字,下劃線numberFt:/^[0-9]+.?[0-9]*$/, //驗證是數字格式,eg:1.11 numberFtMark:/[0-9.]+/, //驗證是數字格式,eg:1.11.234chineseMark:/[\u4E00-\u9FA5\uF900-\uFA2D.\-\(\)]+/,//中文,字母,數字,加入括號mobilePhone:/(^0{0,1}1[3|4|5|6|7|8|9][0-9]{9}$)/,email:/^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.){1,4}[a-z]{2,3}$/},check:function(v,exp,msg){console.info(v+","+exp+","+msg);try{console.info(exp.test(v));if(!exp.test(v)){Jmts.warnTips(msg);//警告框return false;}}catch(e){return false;}return true;},checkNumWord:function(v,msg){return Validator.check(v,Validator.exp.numWord,msg);},checkNumWordM:function(v,msg){return Validator.check(v,Validator.exp.numWordM,msg);},checkChinese:function(v,msg){return Validator.check(v,Validator.exp.chinese,msg);},checkChineseMark:function(v,msg){return Validator.check(v,Validator.exp.chineseMark,msg);},checkNumberFt:function(v,msg){ return Validator.check(v,Validator.exp.numberFt,msg);},checkNumberFtMark:function(v,msg){ return Validator.check(v,Validator.exp.numberFtMark,msg);},checkNumber:function(v,msg){ return Validator.check(v,Validator.exp.numberReg,msg);},checkWord:function(v,msg){ return Validator.check(v,Validator.exp.wordReg,msg);},checkWordAnd_:function(v,msg){ return Validator.check(v,Validator.exp.wordRegAnd_,msg);},checkLetter:function(v,msg){ return Validator.check(v,Validator.exp.letter,msg);},checkMobilePhone:function(v,msg){ return Validator.check(v,Validator.exp.mobilePhone,msg);},checkEmail:function(v,msg){ return Validator.check(v,Validator.exp.email,msg);},isNull:function(v){//如果不為空,那么返回 falseif(v == null || v == undefined || v == ''){return true;}else{return false;}}};
?
2.使用
οnblur="Validator.isNull(this.value)||Validator.checkNumWordM(this.value,'資金流向編號只能是數字或字母!');"
轉載于:https://www.cnblogs.com/yun965861480/p/6274421.html
總結
- 上一篇: 梦到盖房啥意思
- 下一篇: Hibernate的批量操作