分享

easyUI 验证控件应用、自定义、扩展验证 手机号码或电话话码格式

 dabinglibrary 2016-02-17
转:http://blog.csdn.net/liangrui1988/article/details/40145707?utm_source=tuicool&utm_medium=referral

easyui官方demo: http://www./demo/main/index.php?plugin=DataGrid&theme=default&dir=ltr&pitem=#

easyUI 验证控件应用、自定义、扩展验证 手机号码或电话话码格式

在API中   发现给的demo 中没有这个验证,所以就研究了下.

相关介绍省略,直接上代码吧!



[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www./TR/html4/loose.dtd">  
  2. <html>  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  5.   
  6. <title>Insert title here</title>  
  7.     <link rel="stylesheet" type="text/css" href="jquery-easyui-1.4/themes/default/easyui.css"/>      
  8.     <link rel="stylesheet" type="text/css" href="jquery-easyui-1.4/themes/icon.css"/>      
  9.     <script type="text/javascript" src="jquery-easyui-1.4/jquery.min.js"></script>      
  10.     <script type="text/javascript" src="jquery-easyui-1.4/jquery.easyui.min.js"></script>      
  11.     <script type="text/javascript" src="jquery-easyui-1.4/locale/easyui-lang-zh_CN.js"></script>    
  12. </head>  
  13. <body>  
  14.  <h2>Custom ValidateBox Tooltip</h2>  
  15.     <p>This sample shows how to display another tooltip message on a valid textbox.</p>  
  16.     <div style="margin:20px 0;"></div>  
  17.     <div class="easyui-panel" title="Register" style="width:400px;padding:10px 60px 20px 60px">  
  18.         <table cellpadding="5">  
  19.             <tr>  
  20.                 <td>User Name:</td>  
  21.                 <td><input class="easyui-validatebox textbox" data-options="required:true,validType:'length[3,10]'"></td>  
  22.             </tr>  
  23.             <tr>  
  24.                 <td>Email:</td>  
  25.                 <td><input class="easyui-validatebox textbox" data-options="prompt:'Enter a valid email.',required:true,validType:'email'"></td>  
  26.             </tr>  
  27.             <tr>  
  28.                 <td>Birthday:</td>  
  29.                 <td><input class="easyui-datebox"></td>  
  30.             </tr>  
  31.             <tr>  
  32.                 <td>URL:</td>  
  33.                 <td><input class="easyui-validatebox textbox" data-options="prompt:'Enter your URL.',required:true,validType:'url'"></td>  
  34.             </tr>  
  35.             <tr>  
  36.                 <td>Phone:</td>  
  37.                 <td><input class="easyui-validatebox textbox" data-options="prompt:'Enter your phone number.',required:true"></td>  
  38.             </tr>  
  39.               
  40.              <tr>  
  41.                 <td>extneds 联系电话 test:</td>  
  42.                 <td><input class="easyui-validatebox" data-options="validType:'phoneRex'"></td>  
  43.             </tr>  
  44.         </table>  
  45.     </div>  
  46.     <style scoped="scoped">  
  47.         .textbox{  
  48.             height:20px;  
  49.             margin:0;  
  50.             padding:0 2px;  
  51.             box-sizing:content-box;  
  52.         }  
  53.     </style>  
  54.     <script>  
  55.       
  56.       
  57.      //自定义验证  
  58.     $.extend($.fn.validatebox.defaults.rules, {  
  59.     phoneRex: {  
  60.         validator: function(value){  
  61.         var rex=/^1[3-8]+\d{9}$/;  
  62.         //var rex=/^(([0\+]\d{2,3}-)?(0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/;  
  63.         //区号:前面一个0,后面跟2-3位数字 : 0\d{2,3}  
  64.         //电话号码:7-8位数字: \d{7,8  
  65.         //分机号:一般都是3位数字: \d{3,}  
  66.          //这样连接起来就是验证电话的正则表达式了:/^((0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/          
  67.         var rex2=/^((0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/;  
  68.         if(rex.test(value)||rex2.test(value))  
  69.         {  
  70.           // alert('t'+value);  
  71.           return true;  
  72.         }else  
  73.         {  
  74.          //alert('false '+value);  
  75.            return false;  
  76.         }  
  77.             
  78.         },  
  79.         message: '请输入正确电话或手机格式'  
  80.     }  
  81. });  
  82.   
  83.         $(function(){  
  84.             $('input.easyui-validatebox').validatebox({  
  85.                 tipOptions: {    // the options to create tooltip  
  86.                     showEvent: 'mouseenter',  
  87.                     hideEvent: 'mouseleave',  
  88.                     showDelay: 0,  
  89.                     hideDelay: 0,  
  90.                     zIndex: '',  
  91.                     onShow: function(){  
  92.                         if (!$(this).hasClass('validatebox-invalid')){  
  93.                             if ($(this).tooltip('options').prompt){  
  94.                                 $(this).tooltip('update', $(this).tooltip('options').prompt);  
  95.                             } else {  
  96.                                 $(this).tooltip('tip').hide();  
  97.                             }  
  98.                         } else {  
  99.                             $(this).tooltip('tip').css({  
  100.                                 color: '#000',  
  101.                                 borderColor: '#CC9933',  
  102.                                 backgroundColor: '#FFFFCC'  
  103.                             });  
  104.                         }  
  105.                     },  
  106.                     onHide: function(){  
  107.                         if (!$(this).tooltip('options').prompt){  
  108.                             $(this).tooltip('destroy');  
  109.                         }  
  110.                     }  
  111.                 }  
  112.             }).tooltip({  
  113.                 position: 'right',  
  114.                 content: function(){  
  115.                     var opts = $(this).validatebox('options');  
  116.                     return opts.prompt;  
  117.                 },  
  118.                 onShow: function(){  
  119.                     $(this).tooltip('tip').css({  
  120.                         color: '#000',  
  121.                         borderColor: '#CC9933',  
  122.                         backgroundColor: '#FFFFCC'  
  123.                     });  
  124.                 }  
  125.             });  
  126.         });  
  127.     </script>  
  128. </body>  
  129.    
  130. </body>  
  131. </html>  

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多