博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
自定义easy-ui validatebox 如maxLength()等等校验规则
阅读量:6457 次
发布时间:2019-06-23

本文共 2358 字,大约阅读时间需要 7 分钟。

hot3.png

  1. $(document).ready(  
  2.         function(){  
  3.               
  4.             $.extend($.fn.validatebox.defaults.rules, {     
  5.                 minLength: {     
  6.                     validator: function(value, param){   //value 为需要校验的输入框的值 , param为使用此规则时存入的参数  
  7.                         return value.length >= param[0];     
  8.                     },     
  9.                     message: '请输入最小{0}位字符.'    
  10.                 }     
  11.             });   
  12.               
  13.             $.extend($.fn.validatebox.defaults.rules, {     
  14.                 maxLength: {     
  15.                     validator: function(value, param){     
  16.                         return param[0] >= value.length;     
  17.                     },     
  18.                     message: '请输入最大{0}位字符.'    
  19.                 }     
  20.             });   
  21.               
  22.             $.extend($.fn.validatebox.defaults.rules, {     
  23.                 length: {     
  24.                     validator: function(value, param){     
  25.                         return value.length >= param[0] && param[1] >= value.length;     
  26.                     },     
  27.                     message: '请输入{0}-{1}位字符.'    
  28.                 }     
  29.             });   
  30.   
  31.         // extend the 'equals' rule     
  32.             $.extend($.fn.validatebox.defaults.rules, {     
  33.                 equals: {     
  34.                     validator: function(value,param){     
  35.                         return value == $(param[0]).val();     
  36.                     },     
  37.                     message: '字段不相同.'    
  38.                 }     
  39.             });    
  40.               
  41.             $.extend($.fn.validatebox.defaults.rules, {     
  42.                 web : {     
  43.                     validator: function(value){     
  44.                         return /^(http[s]{0,1}|ftp):\/\//i.test($.trim(value));     
  45.                     },     
  46.                     message: '网址格式错误.'    
  47.                 }     
  48.             });   
  49.                           
  50.            $.extend($.fn.validatebox.defaults.rules, {     
  51.                mobile : {     
  52.                     validator: function(value){     
  53.                         return /^1[0-9]{10}$/i.test($.trim(value));     
  54.                     },     
  55.                     message: '手机号码格式错误.'    
  56.                 }     
  57.             });  
  58.              
  59.            $.extend($.fn.validatebox.defaults.rules, {     
  60.                date : {     
  61.                     validator: function(value){     
  62.                         return /^[0-9]{4}[-][0-9]{2}[-][0-9]{2}$/i.test($.trim(value));     
  63.                     },     
  64.                     message: '曰期格式错误,如2012-09-11.'    
  65.                 }     
  66.             });   
  67.              
  68.            $.extend($.fn.validatebox.defaults.rules, {     
  69.                email : {     
  70.                     validator: function(value){     
  71.                         return /^[a-zA-Z0-9_+.-]+\@([a-zA-Z0-9-]+\.)+[a-zA-Z0-9]{2,4}$/i.test($.trim(value));     
  72.                     },     
  73.                     message: '电子邮箱格式错误.'    
  74.                 }     
  75.             });   
  76.              
  77.            $.extend($.fn.validatebox.defaults.rules, {     
  78.                captcha : {     
  79.                     validator: function(value){     
  80.                         var data0 = false;  
  81.                         $.ajax({  
  82.                             type: "POST",async:false,  
  83.                             url:contextPath + "/json/valSimulation.action",  
  84.                             dataType:"json",  
  85.                             data:{
    "simulation":value},  
  86.                             async:false,  
  87.                             success: function(data){  
  88.                                 data0=data;  
  89.                             }  
  90.                         });  
  91.                           
  92.                        return data0;  
  93. //                      return /^[a-zA-Z0-9]{4}$/i.test($.trim(value));  
  94.                     },     
  95.                     message: '验证码错误.'    
  96.                 }     
  97.             });   
  98.              
  99.            $.extend($.fn.validatebox.defaults.rules, {     
  100.                txtName : {     
  101.                     validator: function(value,param){     
  102.                         var data0 = false;  
  103.                         if(value.length >= param[0] && param[1] >= value.length)  
  104.                         {  
  105.                             $.ajax({  
  106.                                 type: "POST",async:false,  
  107.                                 url:contextPath + "/json/valName.action",  
  108.                                 dataType:"json",  
  109.                                 data:{
    "txtName":value},  
  110.                                 async:false,  
  111.                                 success: function(data){  
  112.                                     data0=!data;  
  113.                                 }  
  114.                             });  
  115.                         }else{  
  116.                             param[2] = "请输入"+param[0]+"-"+param[1]+"位字符.";  
  117.                             return false;  
  118.                         }  
  119.                           
  120.                         param[2] = "用户名称已存在.";  
  121.                        return data0;  
  122.                     },     
  123.                     message: "{2}"   
  124.                 }     
  125.             });   
  126.              
  127.     });    

转载于:https://my.oschina.net/sky2008/blog/634566

你可能感兴趣的文章
JSON
查看>>
Java 9进入第一轮问题修复阶段
查看>>
腾讯云一站式物联PaaS平台IOT Suite助力行业加速“物联网+”
查看>>
从初创型到独角兽企业,监控架构演进的那些事儿
查看>>
Grafana 6.0正式发布!新增查询工作流,全新独立Gauge面板
查看>>
runC爆严重安全漏洞,主机可被攻击!使用容器的快打补丁
查看>>
Java 基础类库:System、Runtime、Object、Math、日期、时间
查看>>
InfoQ编辑2018年推荐阅读清单(第二部分)
查看>>
Buoyant发布服务网格Linkerd的1.0版本
查看>>
函数式编程能否支持更高效的区块链基础设施?
查看>>
AWS Amplify Console:赋予应用程序快速部署的能力
查看>>
ThoughtWorks雷达上的新奇变化
查看>>
Respo 首屏 DOM 更新的方案, CSS 动画的 Demo
查看>>
vue的第一份正式源码
查看>>
vue2.0一起在懵逼的海洋里越陷越深(二)
查看>>
PJAX,站点加速之翼
查看>>
CSS+JS实现苹果cover flow效果
查看>>
玄学之问题
查看>>
nodejs通过later实现定时执行任务
查看>>
[System Design] 系统设计 (2) -- 数据库设计
查看>>