validate 扩展js

$.extend($.fn.validatebox.defaults.rules, {
equals: {
validator: function(value,param){
return value == $(param[0]).val();
},
message: '两次输入内容不一致'
},
minLength: {
validator: function(value, param){
return value.length >= param[0];
},
message: 'Please enter at least {0} characters.'
},
//手机号码
mobile: {
validator: function(value, param){
return /^0{0,1}1[3,8,5][0-9]{9}$/.test(value);
},
message: "手机号码格式不正确"
},
//身份证
IDCard: {
validator: function(value, param){
return /^\d{15}(\d{2}[A-Za-z0-9])?$/i.test(value);
},
message: "请输入正确的身份证号码"
},
//比较时间选择器
compareDate: {
validator: function(value, param){
return dateCompare($(param[0]).datebox("getValue"), value);
},
message: "结束日期不能小于开始日期"
},
// 验证是否包含空格和非法字符
unnormal: {
validator: function (value) {
return /^[a-zA-Z0-9]/i.test(value); },
message: '输入值不能为空和包含其他非法字符'
},
//过滤特殊字符
filterSpecial:{
validator: function(value, param){ //过滤空格
var flag = /\s/.test(value);
//过滤特殊字符串
var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】’‘《》;:”“'。,、?]");
var specialFlag = pattern.test(value);
return !flag && !specialFlag;
},
message: "非法字符,请重新输入"
},
checkNum: {
validator: function(value, param) {
return /^([0-9]+)$/.test(value);
},
message: '请输入整数'
},
checkFloat: {
validator: function(value, param) {
return /^[+|-]?([0-9]+\.[0-9]+)|[0-9]+$/.test(value);
},
message: '请输入合法数字'
},
length:{validator:function(value,param){
var len=$.trim(value).length;
return len>=param[0]&&len<=param[1];
},
message:"输入内容长度必须介于{0}和{1}之间."
},
phone : {// 验证电话号码
validator : function(value) {
return /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/i.test(value);
},
message : '格式不正确,请使用下面格式:020-88888888'
},
intOrFloat : {// 验证整数或小数
validator : function(value) {
return /^\d+(\.\d+)?$/i.test(value);
},
message : '请输入数字,并确保格式正确'
},
qq : {// 验证QQ,从10000开始
validator : function(value) {
return /^[1-9]\d{5,9}$/i.test(value);
},
message : 'QQ号码格式不正确'
},
age : {// 验证年龄
validator : function(value) {
return /^(?:[1-9][0-9]?|1[01][0-9]|120)$/i.test(value);
},
message : '年龄必须是0到120之间的整数'
}, chinese : {// 验证中文
validator : function(value) {
return /^[\Α-\¥]+$/i.test(value);
},
message : '请输入中文'
},
english : {// 验证英语
validator : function(value) {
return /^[A-Za-z]+$/i.test(value);
},
message : '请输入英文'
},
username : {// 验证用户名
validator : function(value) {
return /^[a-zA-Z][a-zA-Z0-9_]{5,15}$/i.test(value);
},
message : '用户名不合法(字母开头,允许6-16字节,允许字母数字下划线)'
},
faxno : {// 验证传真
validator : function(value) {
// return /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/i.test(value);
return /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/i.test(value);
},
message : '传真号码不正确'
},
zip : {// 验证邮政编码
validator : function(value) {
return /^[1-9]\d{5}$/i.test(value);
},
message : '邮政编码格式不正确'
},
ip : {// 验证IP地址
validator : function(value) {
return /^((([01]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))[.]){3}(([0-1]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))$/i.test(value);
},
message : 'IP地址格式不正确'
},
name : {// 验证姓名,可以是中文或英文
validator : function(value) {
return /^[\Α-\¥]+$/i.test(value)|/^\w+[\w\s]+\w+$/i.test(value);
},
message : '请输入中文或英文的姓名'
},
date : {// 输入合适的日期格式 yyyy-MM-dd或yyyy-M-d
validator : function(value) {
//格式yyyy-MM-dd或yyyy-M-d
return /^(?:(?!0000)[0-9]{4}([-]?)(?:(?:0?[1-9]|1[0-2])\1(?:0?[1-9]|1[0-9]|2[0-8])|(?:0?[13-9]|1[0-2])\1(?:29|30)|(?:0?[13578]|1[02])\1(?:31))|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)([-]?)0?2\2(?:29))$/i.test(value);
},
message : '清输入合适的日期格式'
}
}); /*
* 比较两个日期的大小
* 传入的参数推荐是"yyyy-mm-dd"的格式,其他的日期格式也可以,但要保证一致
*/
var dateCompare = function(date1, date2){
if(date1 && date2){
var a = new Date(date1);
var b = new Date(date2);
return a < b;
}
}

用例

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Validate On Blur - jQuery EasyUI Demo</title>
<link rel="stylesheet" type="text/css" href="../../themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../../themes/icon.css">
<link rel="stylesheet" type="text/css" href="../demo.css">
<script type="text/javascript" src="../../jquery.min.js"></script>
<script type="text/javascript" src="../../jquery.easyui.min.js"></script>
<script type="text/javascript" src="../../jquery.easyui.validation.js"></script>
</head>
<body>
<center>
<h2 id="top">Validate</h2>
<div style="margin:20px 0;"></div>
<div class="easyui-panel" title="常用" style="width:100%;max-width:400px;padding:30px 60px;">
<div style="margin-bottom:20px">
<label for="username" class="label-top">长度范围限制(3-10)</label>
<input id="username" class="easyui-validatebox tb" data-options="required:true,validType:'length[3,10]',validateOnCreate:false,validateOnBlur:true,err:err">
</div>
<div style="margin-bottom:20px">
<label for="email" class="label-top">Email格式验证</label>
<input id="email" class="easyui-validatebox tb" data-options="required:true,validType:'email',validateOnCreate:false,validateOnBlur:true,tipPosition:'left'">
</div>
<div style="margin-bottom:20px">
<label for="url" class="label-top">Url格式验证</label>
<input id="url" class="easyui-validatebox tb" data-options="required:true,validType:'url',validateOnCreate:false,validateOnBlur:true" tipPosition="right">
</div>
<div style="margin-bottom:20px">
<label for="phone" class="label-top">密码:</label>
<input id="phone" class="easyui-passwordbox" prompt="Password" data-options="required:true,validateOnCreate:false,validateOnBlur:true" tipPosition="top">
</div>
<div style="margin-bottom:20px">
<label for="phone" class="label-top">确认密码:</label>
<input id="rephone" class="easyui-passwordbox" prompt="RePassword" data-options="required:true,validateOnCreate:false,validateOnBlur:true" validType="equals['#phone']" tipPosition="bottom">
</div>
<div style="margin-bottom:20px">
<label for="username" class="label-top">限制最小长度5个字符:</label>
<input id="username" class="easyui-validatebox tb" data-options="required:true,validateOnCreate:false,validateOnBlur:true" validType='minLength[5]'>
</div>
<div style="margin-bottom:20px">
<label for="username" class="label-top">手机号码:</label>
<input id="username" class="easyui-validatebox tb" data-options="required:true,validType:'mobile',validateOnCreate:false,validateOnBlur:true,err:err">
</div>
<div style="margin-bottom:20px">
<label for="username" class="label-top">身份证号:</label>
<input id="username" class="easyui-validatebox tb" data-options="required:true,validType:'IDCard',validateOnCreate:false,validateOnBlur:true,err:err">
</div>
</div>
<div style="margin:20px 0;"></div>
<div class="easyui-panel" title="数字" style="width:100%;max-width:400px;padding:30px 60px;">
<div style="margin-bottom:20px">
<label for="username" class="label-top">输入整数:</label>
<input id="username" class="easyui-validatebox tb" data-options="required:true,validType:'checkNum',validateOnCreate:false,validateOnBlur:true">
</div>
<div style="margin-bottom:20px">
<label for="username" class="label-top">合法数字:</label>
<input id="username" class="easyui-validatebox tb" data-options="required:true,validType:'checkFloat',validateOnCreate:false,validateOnBlur:true">
</div>
<div style="margin-bottom:20px">
<label for="username" class="label-top">验证电话号码:</label>
<input id="username" class="easyui-validatebox tb" data-options="required:true,validType:'phone',validateOnCreate:false,validateOnBlur:true">
</div>
<div style="margin-bottom:20px">
<label for="username" class="label-top">验证整数或小数 :</label>
<input id="username" class="easyui-validatebox tb" data-options="required:true,validType:'intOrFloat',validateOnCreate:false,validateOnBlur:true">
</div>
<div style="margin-bottom:20px">
<label for="username" class="label-top">验证QQ,从10000开始:</label>
<input id="username" class="easyui-validatebox tb" data-options="required:true,validType:'qq',validateOnCreate:false,validateOnBlur:true">
</div>
<div style="margin-bottom:20px">
<label for="username" class="label-top">验证年龄:</label>
<input id="username" class="easyui-validatebox tb" data-options="required:true,validType:'age',validateOnCreate:false,validateOnBlur:true">
</div>
</div>
<div style="margin:20px 0;"></div>
<div class="easyui-panel" title="字符串" style="width:100%;max-width:400px;padding:30px 60px;">
<div style="margin-bottom:20px">
<label for="username" class="label-top">输入内容长度必须介于{0}和{1}之间:</label>
<input id="username" class="easyui-validatebox tb" data-options="required:true,validType:'length[2,4]',validateOnCreate:false,validateOnBlur:true">
</div>
<div style="margin-bottom:20px">
<label for="username" class="label-top">验证是否包含空格和非法字符:</label>
<input id="username" class="easyui-validatebox tb" data-options="required:true,validType:'unnormal',validateOnCreate:false,validateOnBlur:true">
</div>
<div style="margin-bottom:20px">
<label for="username" class="label-top">过滤特殊字符:</label>
<input id="username" class="easyui-validatebox tb" data-options="required:true,validType:'filterSpecial',validateOnCreate:false,validateOnBlur:true">
</div>
<div style="margin-bottom:20px">
<label for="username" class="label-top">验证中文:</label>
<input id="username" class="easyui-validatebox tb" data-options="required:true,validType:'chinese',validateOnCreate:false,validateOnBlur:true">
</div>
<div style="margin-bottom:20px">
<label for="username" class="label-top">验证英语 :</label>
<input id="username" class="easyui-validatebox tb" data-options="required:true,validType:'english',validateOnCreate:false,validateOnBlur:true">
</div>
<div style="margin-bottom:20px">
<label for="username" class="label-top">用户名不合法(字母开头,允许6-16字节,允许字母数字下划线):</label>
<input id="username" class="easyui-validatebox tb" data-options="required:true,validType:'username',validateOnCreate:false,validateOnBlur:true">
</div>
<div style="margin-bottom:20px">
<label for="username" class="label-top">验证姓名,可以是中文或英文 :</label>
<input id="username" class="easyui-validatebox tb" data-options="required:true,validType:'name',validateOnCreate:false,validateOnBlur:true">
</div>
<div style="margin-bottom:20px">
<label for="username" class="label-top">验证传真 3-4位数字'-'7-8位数字或7-8位数字(519-85125379或85125379):</label>
<input id="username" class="easyui-validatebox tb" data-options="required:true,validType:'faxno',validateOnCreate:false,validateOnBlur:true">
</div>
<div style="margin-bottom:20px">
<label for="username" class="label-top">验证邮政编码(非0开头6位数字):</label>
<input id="username" class="easyui-validatebox tb" data-options="required:true,validType:'zip',validateOnCreate:false,validateOnBlur:true">
</div>
<div style="margin-bottom:20px">
<label for="username" class="label-top">验证IP地址 :</label>
<input id="username" class="easyui-validatebox tb" data-options="required:true,validType:'ip',validateOnCreate:false,validateOnBlur:true">
</div>
</div>
<div style="margin:20px 0;"></div>
<div class="easyui-panel" title="日期" style="width:100%;max-width:400px;padding:30px 60px;">
<div style="margin-bottom:20px">
<label for="username" class="label-top">输入合适的日期格式 yyyy-MM-dd :</label>
<input id="username" style="width:100%;" class="easyui-datebox tb" data-options="required:true,validType:'date',validateOnCreate:false,validateOnBlur:true,formatter:myformatter,parser:myparser">
</div>
<div style="margin-bottom:20px">
<label for="username" class="label-top">结束日期不能小于开始日期:</label>
<input id="date1" style="width:100%;" class="easyui-datebox tb " data-options="required:true,validateOnCreate:false,validateOnBlur:true,formatter:myformatter,parser:myparser">
</div>
<div style="margin-bottom:20px">
<label for="username" class="label-top">结束日期不能小于开始日期:</label>
<input id="date2" style="width:100%;" class="easyui-datebox tb " data-options="required:true,validateOnCreate:false,validateOnBlur:true,formatter:myformatter,parser:myparser" validType="compareDate['#date1']">
</div>
</div>
<a href="#top"><img src="top.gif" style="position: fixed;right: 30px;bottom: 20px;" width="20" height="30"/></a>
<style scoped="scoped">
.tb{
width:100%;
margin:0;
padding:5px 4px;
border:1px solid #ccc;
box-sizing:border-box;
}
</style>
<!-- 设置错误提示显示在下方 -->
<script type="text/javascript">
function err(target, message){
var t = $(target);
if (t.hasClass('textbox-text')){
t = t.parent();
}
var m = t.next('.error-message');
if (!m.length){
m = $('<div class="error-message"></div>').insertAfter(t);
}
m.html(message);
}
function myformatter(date){
var y = date.getFullYear();
var m = date.getMonth()+1;
var d = date.getDate();
return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
}
function myparser(s){
if (!s) return new Date();
var ss = (s.split('-'));
var y = parseInt(ss[0],10);
var m = parseInt(ss[1],10);
var d = parseInt(ss[2],10);
if (!isNaN(y) && !isNaN(m) && !isNaN(d)){
return new Date(y,m-1,d);
} else {
return new Date();
}
}
</script>
</center>
</body>
</html>

  

JQuery EasyUI validate 扩展的更多相关文章

  1. Jquery Easyui验证扩展,Easyui验证,Easyui校验,js正则表达式

    Jquery Easyui验证扩展,Easyui验证,Easyui校验,js正则表达式 >>>>>>>>>>>>>> ...

  2. jquery easyui的扩展验证

    1.扩展通过$.extends($.fn.validatebox.defaults.rules,)扩展 $.extend( $.fn.validatebox.defaults.rules, { idc ...

  3. 封装jQuery Validate扩展验证方法

    一.封装自定义验证方法-validate-methods.js /***************************************************************** j ...

  4. [转]jQuery EasyUI 扩展-- 主题(Themes)

    主题(Themes)允许您改变站点的外观和感观.使用主题可以节省设计的时间,让您腾出更多的时间进行开发.您也可以创建一个已有主题的子主题. 主题生成器(Theme Builder) jQuery UI ...

  5. 扩展jquery easyui datagrid编辑单元格

    扩展jquery easyui datagrid编辑单元格 1.随便聊聊 这段时间由于工作上的业务需求,对jquery easyui比较感兴趣,根据比较浅薄的js知识,对jquery easyui中的 ...

  6. jquery validate扩展验证方法

    /***************************************************************** jQuery Validate扩展验证方法 (linjq) *** ...

  7. 雷林鹏分享:jQuery EasyUI 数据网格 - 扩展编辑器

    jQuery EasyUI 数据网格 - 扩展编辑器 一些常见的编辑器(editor)添加到数据网格(datagrid),以便用户编辑数据. 所有的编辑器(editor)都定义在 $.fn.datag ...

  8. 雷林鹏分享:jQuery EasyUI 扩展

    jQuery EasyUI 扩展 Portal(制作图表.列表.球形图等) 数据网格视图(DataGrid View) 可编辑的数据网格(Editable DataGrid) 可编辑的树(Editab ...

  9. easyui validate -- radio、checkbox 校验扩展,事件域名

    事件域名: $(dom).on('click.myNameSpace',function(){ ... }),其中‘.myNameSpace’便是域名: 目前作用:$(dom).off('click. ...

随机推荐

  1. power law 幂定律

    y=cx∧a 卖品销量排名与销量

  2. Delphi 完全时尚手册之 Visual Style 篇

    这里先说说两个概念:Theme(主题)和 Visual Style .Theme 最早出现在 Microsoft Plus! for Windows 95 中,是 Windows 中 Wallpape ...

  3. 【题解】 P5021赛道修建

    [题解]P5021 赛道修建 二分加贪心,轻松拿省一(我没有QAQ) 题干有提示: 输出格式: 输出共一行,包含一个整数,表示长度最小的赛道长度的最大值. 注意到没,最小的最大值,还要多明显? 那么我 ...

  4. 【ELK】ELK5.3搭建过程遇到的问题

    elasticsearch 5.3 安装过程中遇到了一些问题,这里简单记录一下 . 问题一:警告提示 [2016-11-06T16:27:21,712][WARN ][o.e.b.JNANatives ...

  5. log4net 初步使用

    自从知道了log4net之后,就一直使用的它,一直没有问题,最近由于项目变动,便将一部分的代码分离出来,然后咋UI项目中调用loghelper,便发现在本地测试一切正常,可是发布到服务器之后便不正常了 ...

  6. 架构设计:系统间通信(34)——被神化的ESB(上)

    1.概述 从本篇文章开始,我们将花一到两篇的篇幅介绍ESB(企业服务总线)技术的基本概念,为读者们理清多个和ESB技术有关名词.我们还将在其中为读者阐述什么情况下应该使用ESB技术.接下来,为了加深读 ...

  7. android程序的真正入口

    代码出自MtAndroid 3.1.2完全开发手册,适用于Android平台. 概述 android程序的真正入口是Application类的onCreate方法.它的继承关系如下所示: java.l ...

  8. java 基础 - 查找某个字串出现的次数及位置

    查找某个字串出现的次数及位置 public class search { public static void main(String[] args){ String str = "abc1 ...

  9. IntelliJ IDEA 同时启动多个Tomcat实例端口是会冲突

  10. Git_学习_02_ 分支

    Git鼓励大量使用分支: 1.查看分支:git branch 2.创建分支:git branch <name> 3.切换分支:git checkout <name> 4.创建+ ...