EasyUI 扩展自定义EasyUI校验规则 验证规则(常用的)

转自:http://blog.csdn.net/pqszq1314/article/details/25896163
例如 校验输入框只能录入0-1000之间 最多有2位小数的数字

表单<input type="text" id="rate" name="rate" required="true" class="easyui-validatebox"  validType="rateCheck[0,1000]"  maxlength="6" />

EasyUI 扩展自定义EasyUI校验规则 验证规则(常用的)_第1张图片


[html]  view plain copy
  1. $.extend($.fn.validatebox.defaults.rules, {  
  2.                 CHS: {  
  3.                     validator: function (value, param) {  
  4.                         return /^[\u0391-\uFFE5]+$/.test(value);  
  5.                     },  
  6.                     message: '请输入汉字'  
  7.                 },  
  8.                 english : {// 验证英语  
  9.                     validator : function(value) {  
  10.                         return /^[A-Za-z]+$/i.test(value);  
  11.                     },  
  12.                     message : '请输入英文'  
  13.                 },  
  14.                 ip : {// 验证IP地址  
  15.                     validator : function(value) {  
  16.                         return /\d+\.\d+\.\d+\.\d+/.test(value);  
  17.                     },  
  18.                     message : 'IP地址格式不正确'  
  19.                 },  
  20.                 ZIP: {  
  21.                     validator: function (value, param) {  
  22.                         return /^[0-9]\d{5}$/.test(value);  
  23.                     },  
  24.                     message: '邮政编码不存在'  
  25.                 },  
  26.                 QQ: {  
  27.                     validator: function (value, param) {  
  28.                         return /^[1-9]\d{4,10}$/.test(value);  
  29.                     },  
  30.                     message: 'QQ号码不正确'  
  31.                 },  
  32.                 mobile: {  
  33.                     validator: function (value, param) {  
  34.                         return /^(?:13\d|15\d|18\d)-?\d{5}(\d{3}|\*{3})$/.test(value);  
  35.                     },  
  36.                     message: '手机号码不正确'  
  37.                 },  
  38.                 tel:{  
  39.                     validator:function(value,param){  
  40.                         return /^(\d{3}-|\d{4}-)?(\d{8}|\d{7})?(-\d{1,6})?$/.test(value);  
  41.                     },  
  42.                     message:'电话号码不正确'  
  43.                 },  
  44.                 mobileAndTel: {  
  45.                     validator: function (value, param) {  
  46.                         return /(^([0\+]\d{2,3})\d{3,4}\-\d{3,8}$)|(^([0\+]\d{2,3})\d{3,4}\d{3,8}$)|(^([0\+]\d{2,3}){0,1}13\d{9}$)|(^\d{3,4}\d{3,8}$)|(^\d{3,4}\-\d{3,8}$)/.test(value);  
  47.                     },  
  48.                     message: '请正确输入电话号码'  
  49.                 },  
  50.                 number: {  
  51.                     validator: function (value, param) {  
  52.                         return /^[0-9]+.?[0-9]*$/.test(value);  
  53.                     },  
  54.                     message: '请输入数字'  
  55.                 },  
  56.                 money:{  
  57.                     validator: function (value, param) {  
  58.                         return (/^(([1-9]\d*)|\d)(\.\d{1,2})?$/).test(value);  
  59.                      },  
  60.                      message:'请输入正确的金额'  
  61.   
  62.                 },  
  63.                 mone:{  
  64.                     validator: function (value, param) {  
  65.                         return (/^(([1-9]\d*)|\d)(\.\d{1,2})?$/).test(value);  
  66.                      },  
  67.                      message:'请输入整数或小数'  
  68.   
  69.                 },  
  70.                 integer:{  
  71.                     validator:function(value,param){  
  72.                         return /^[+]?[1-9]\d*$/.test(value);  
  73.                     },  
  74.                     message: '请输入最小为1的整数'  
  75.                 },  
  76.                 integ:{  
  77.                     validator:function(value,param){  
  78.                         return /^[+]?[0-9]\d*$/.test(value);  
  79.                     },  
  80.                     message: '请输入整数'  
  81.                 },  
  82.                 range:{  
  83.                     validator:function(value,param){  
  84.                         if(/^[1-9]\d*$/.test(value)){  
  85.                             return value >= param[0] && value <= param[1]  
  86.                         }else{  
  87.                             return false;  
  88.                         }  
  89.                     },  
  90.                     message:'输入的数字在{0}到{1}之间'  
  91.                 },  
  92.                 minLength:{  
  93.                     validator:function(value,param){  
  94.                         return value.length >=param[0]  
  95.                     },  
  96.                     message:'至少输入{0}个字'  
  97.                 },  
  98.                 maxLength:{  
  99.                     validator:function(value,param){  
  100.                         return value.length<=param[0]  
  101.                     },  
  102.                     message:'最多{0}个字'  
  103.                 },  
  104.                 //select即选择框的验证  
  105.                 selectValid:{  
  106.                     validator:function(value,param){  
  107.                         if(value == param[0]){  
  108.                             return false;  
  109.                         }else{  
  110.                             return true ;  
  111.                         }  
  112.                     },  
  113.                     message:'请选择'  
  114.                 },  
  115.                 idCode:{  
  116.                     validator:function(value,param){  
  117.                         return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(value);  
  118.                     },  
  119.                     message: '请输入正确的身份证号'  
  120.                 },  
  121.                 loginName: {  
  122.                     validator: function (value, param) {  
  123.                         return /^[\u0391-\uFFE5\w]+$/.test(value);  
  124.                     },  
  125.                     message: '登录名称只允许汉字、英文字母、数字及下划线。'  
  126.                 },  
  127.                 equalTo: {  
  128.                     validator: function (value, param) {  
  129.                         return value == $(param[0]).val();  
  130.                     },  
  131.                     message: '两次输入的字符不一至'  
  132.                 },  
  133.                 englishOrNum : {// 只能输入英文和数字  
  134.                     validator : function(value) {  
  135.                         return /^[a-zA-Z0-9_ ]{1,}$/.test(value);  
  136.                     },  
  137.                     message : '请输入英文、数字、下划线或者空格'  
  138.                 },  
  139.                xiaoshu:{   
  140.                 validator : function(value){   
  141.                 return /^(([1-9]+)|([0-9]+\.[0-9]{1,2}))$/.test(value);  
  142.                 },   
  143.                 message : '最多保留两位小数!'      
  144.                 },  
  145.             ddPrice:{  
  146.                 validator:function(value,param){  
  147.                     if(/^[1-9]\d*$/.test(value)){  
  148.                         return value >= param[0] && value <= param[1];  
  149.                     }else{  
  150.                         return false;  
  151.                     }  
  152.                 },  
  153.                 message:'请输入1到100之间正整数'  
  154.             },  
  155.             jretailUpperLimit:{  
  156.                 validator:function(value,param){  
  157.                     if(/^[0-9]+([.]{1}[0-9]{1,2})?$/.test(value)){  
  158.                         return parseFloat(value) > parseFloat(param[0]) && parseFloat(value) <= parseFloat(param[1]);  
  159.                     }else{  
  160.                         return false;  
  161.                     }  
  162.                 },  
  163.                 message:'请输入0到100之间的最多俩位小数的数字'  
  164.             },  
  165.             rateCheck:{  
  166.                 validator:function(value,param){  
  167.                     if(/^[0-9]+([.]{1}[0-9]{1,2})?$/.test(value)){  
  168.                         return parseFloat(value) > parseFloat(param[0]) && parseFloat(value) <= parseFloat(param[1]);  
  169.                     }else{  
  170.                         return false;  
  171.                     }  
  172.                 },  
  173.                 message:'请输入0到1000之间的最多俩位小数的数字'  
  174.             }  
  175.             });  

你可能感兴趣的:(jquery,easyui,Validator)