# ye.check **Repository Path**: joleye/ye.check ## Basic Information - **Project Name**: ye.check - **Description**: 一个简单的表单管理工具 - **Primary Language**: Unknown - **License**: GPL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-03-11 - **Last Updated**: 2025-11-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: 表单验证 ## README ye.check ======== # 一个简单的表单验证控件 克隆到本地后使用 克隆方法:git clone https://github.com/joleye/ye.check.git 说明:需要jQuery库 演示:http://joleye.github.io/ye.check/demo-verify.html ### 方法说明 ```js ye.verify('.form1').do_post({ method : 'ajax', //默认 ajax模式提交 ajax/post msg : { right : 'dright',//验证正确后的样式规则 error : 'derr'//验证失败后的样式规则 }, btn : { name : '#post',//确定按钮名称 jquery筛选器 text : 'load...', //等待文字 duplicate: true, //允许重复提交 }, errorCallback : function(){}, //验证消息出错回调方法 beforeCallback : function(){},//验证表单成功, 提交表单前触发, return true提交 return false中断 success : function(res){}, //提交成功后调用 res 返回对象 failed : function(xhr){} //提交失败后调用 如:400 , 500错误 }); ``` ##### 枚举方式验证 > arg1:规则,arg2:错误提示,arg3:正确提示,arg4:是否必须,默认必须 ```js ye.check({ 'username' : [ 'require', '不能为空', ' ' ], 'password' : [ 'require', '不能为空', ' ' ], 'mobile' : [ 'mobile', '不能为空', ' ' ], 'idcard' : [ 'idcard', '不能为空', ' ' ], 'sex' : [ 'radio', '不能为空', ' ' ], 'age' : [ 'age', '年龄格式错误', ' ' ], 'ip' : [ 'ip2', '@errmsg', ' ' ], //'ip' : [ 'require', 'ip格式错误', ' '], 'ip' : [ 'require', correct_func, correct_func] //支持自定义消息 }).do_post({ msg : { right : 'dright', error : 'derr' }, form : ye.g('form1'), btn : { name : 'post', text : 'load...' } }); function correct_func(index, id, rule, val){ if(index == 1){ return '错误'; }else if(index == 2){ return '正确'; } } ``` ##### 寄存验证 ```js ye.verify('#form1').do_post({ method : 'ajax',//默认 ajax模式提交 dataType : 'json',//可选 contentType : 'application/json;charset=UTF-8',//可选 msg : { right : 'dright', error : 'derr' }, btn : { name : '#post', text : 'load...', duplicate: false }, success : function(res){ //成功回调 alert(res); }, failed : function(xhr){ //错误回调 , 500错误等 alert(xhr); }, errorCallback : function(){ //验证错误回调 alert('验证信息出错了'); }, beforeCallback : function(){ //提交表单前触发 return true; } }); ``` ##### 默认验证方法列表 >eg: > >属性说明 check-rule: 规则, check-warning: 错误提示消息 check-correct: 正确提示消息, check-show-label: 错误提示标签是否显示 > >mobile 11位的手机号码 > >email 电子邮件地址 如 : testmail@gmail.com > >date 日期格式验证 如 : 2015-1-1 > >require 必填字段 > >require0 必填字段 默认为0情况 > >sex 性别 > >radio 单选, 必选 根据name读取多个值 > >int 整数, 数字 > >price 价格 如: 5.10 > >phone 电话号码 如: 11位手机号, 3-5位带区号的座机, 或带4位分机 > >idcard 身份证号码, 15或18位 > >age 年龄, 需要属性配置 check-conf="{agestart : 6, ageend : 18}" > >ip ip地址 > >null 是否为空 undefined, null ,'' ### 验证方法扩展 >返回参数:2/bool/object > > object格式说明: > > status: true/false > > msg: 消息内容 ```js /*IP验证*/ var errmsg = ""; ye.extend({ ip2: function (id) { var d = ye.g(id).value; if (d == '') { errmsg = '不能为空'; return false; } else { if (!ye._ip(id)) { errmsg = '格式错误'; return false; } else { return true; } } }, custom2: function (id, val) { if(val < 10) { return {status: false, msg: '不能小于10'} }else{ return {status: true, msg: '棒极了'} } } }) ``` >验证使用 ```js var rule = {'ip' : [ 'ip2', '@errmsg', ' ' ]} ``` ### 操作符号说明 ```js var rule = {'ip' : [ 'ip|null', '正确', '只能填写ip地址或者为空' ]} var rule = {'ip' : [ 'require&int', '正确', '只能填写ip地址或者为空' ]} ``` ### 示例文件说明 >demo.html 演示文档 > >demo-verify.html 规则写在文本框中的属性演示 > >demo2.html 组合验证示例