var value=" 23 4 "; var reg=/^[\s ]|[ ]$/gi; return !reg.test(value); //return !(/^\s+|\s+$/.test(value));
var rulesConfig = { idcard: {// 验证身份证 validator: function (value) { return /^\d{15}(\d{2}[A-Za-z0-9])?$/i.test(value); }, message: '身份证号码格式不正确' }, minLength: { validator: function (value, param) { return value.length >= param[0]; }, message: '请输入至少(2)个字符.' }, 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' }, mobile: {// 验证手机号码 validator: function (value) { return /^(13|15|18)\d{9}$/i.test(value); }, message: '手机号码格式不正确' }, currency: {// 验证货币 validator: function (value) { return /^\d+(\.\d+)?$/i.test(value); }, message: '货币格式不正确' }, decimal: { validator: function (value, param) { var regStr = "^\\d+(\\.\\d+)?$"; if (param) regStr = "^\\+?(\\d*\\.\\d{" + param[0] + "})$"; var reg = new RegExp(regStr); return reg.test(value); }, message: '输入的数据格式不正确' }, intOrFloat: {// 验证整数或小数 validator: function (value, param) { var pattStr = "^\\d+(\\.\\d+)?$"; if (param) { pattStr = "^\\d+(\\.\\d{0," + param[0] + "})?$"; } return (new RegExp(pattStr)).test(value); //如果有参数则验证小数的保留位数,下面是原正则表达式 //return /^\d+(\.\d+)?$/i.test(value); }, message: '请输入数字,并确保格式正确' }, integer: {// 验证整数 validator: function (value, param) { var pattern = /^[+]?[0-9]+\d*$/i; if (param) pattern = new RegExp("^[0-9]\d{" + param[0] + "}$"); return pattern.test(value); }, message: '请输入整数' }, range: { validator: function (value, param) { var v1 = parseFloat(param[0]), v2 = parseFloat(value), v3 = parseFloat(param[1]); if (isNaN(v1) || isNaN(v2) || isNaN(v3)) { return false; } return (v1 <= v2 && v2 <= v3); }, message: '请输入{0}到{1}之间的数字' }, qq: {// 验证QQ,从10000开始 validator: function (value) { return /^[1-9]\d{4,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, param) { var pattern = new RegExp("^[\u4e00-\u9fa5]{" + param[0] + "," + param[1] + "}$"); return pattern.test(value); //return /^[\Α-\¥]+$/i.test(value); }, message: '请输入中文' }, english: {// 验证英语 validator: function (value) { return /^[A-Za-z]+$/i.test(value); }, message: '请输入英文' }, unnormal: {// 验证是否包含空格和非法字符 validator: function (value) { return /.+/i.test(value); }, message: '输入值不能为空和包含其他非法字符' }, username: {// 验证用户名 validator: function (value) { return /^[a-zA-Z][a-zA-Z0-9_]{5,15}$/i.test(value); }, message: '用户名不合法(字母开头,允许6-16字节,允许字母数字下划线)' }, address: { validator: function (value) { var reg = /^[< >]+$/; return !reg.test(value);//匹配是否含有特殊的字符 }, message: '只能输入包括汉字、字母、数字、符号' }, 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 /d+.d+.d+.d+/i.test(value); }, message: 'IP地址格式不正确' }, name: {// 验证姓名,可以是中文或英文 validator: function (value) { return /^[\Α-\¥]+$/i.test(value) | /^\w+[\w\s]+\w+$/i.test(value); }, message: '请输入姓名' }, date: {// 验证姓名,可以是中文或英文 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: '清输入合适的日期格式' }, msn: { validator: function (value) { return /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(value); }, message: '请输入有效的msn账号(例:abc@hotnail(msn/live).com)' }, equals: { validator: function (value, param) { if ($("#" + param[0]).val() != "" && value != "") { return $("#" + param[0]).val() == value; } else { return true; } }, message: '两次输入的密码不一致!' }, compareDate: { validator: function (value, param) { return dateCompare($(param[0]).datetimebox('getValue'), value); //注意easyui 时间控制获取值的方式 }, message: '开始日期不能大于结束日期' }, linkMan: { validator: function (value, param) { var pattern = /^[\u4e00-\u9fa5]{2,4}$|^[a-zA-Z]{2,20}$/gi; return pattern.test(value); }, message: "请输入2-4个汉字或者20个字母" }, phoneMobile: {//手机或者固话 validator: function (value, param) { var pattern = /(^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$)|(^((\(\d{3}\))|(\d{3}\-))?(1[358]\d{9})$)/; return pattern.test(value); }, message: "请输入固话或者手机号" }, postCode: { validator: function (value, param) { //var pattern = /^[1-9]\d{5}$/; var pattern = /^[0-9]\d{5}$/; return pattern.test(value); }, message: "请输入邮编" }, product: { validator: function (value, param) { var pattern = new RegExp("^([\u4e00-\u9fa5]|[,]|[,]|[“]|[”]|[\"]|[\"]){" + param[0] + "," + param[1] + "}$"); return pattern.test(value); }, message: "请输入主要产品" }, companyCode: { validator: function (value, param) { var pattern = new RegExp("[a-zA-Z0-9]{8}-[a-zA-Z0-9]"); return pattern.test(value); }, message: "请输入组织机构代码证" }, flEmpty: { validator: function (value, param) { var reg=/^[\s ]|[ ]$/gi; return !reg.test(value); //return !(/^\s+|\s+$/.test(value)); }, message: "首尾不能有空格" }, timeDiff: {//时间范围验证 validator: function (value, param) { //validType:'timeDiff[]' if (param != undefined && param.length == 2) { try { var d1 = null, curd =new Date(value.replace(/-/g, "/")), d3 = null; if (param[0] == 0) {//第一个参数=0 那么必须小于等于第二个参数 d3 = new Date(param[1].replace(/-/g, "/")); rulesConfig.timeDiff.message = "您选择的时间必须大于等于{0}。"; return (curd <= d3); } else if (param[1] == 0) {//第二个参数=0 那么必须大于等于第一个参数 d1 = new Date(param[0].replace(/-/g, "/")); rulesConfig.timeDiff.message = "您选择的时间必须大于等于{0}。"; return (curd >= d1); } else { d1 = new Date(param[0].replace(/-/g, "/")); d3 = new Date(param[1].replace(/-/g, "/")); rulesConfig.timeDiff.message = "您选择的时间必须在{0}和{1}之间。"; return (d1 <= curd <= d3); } }catch(e){ rulesConfig.timeDiff.message = "您选择的时间不正确。"; return false; } return false; } return true; /* var d = new Date(value.replace(/-/g, "/")) var d1 = null; var d2 = null; if (param[0] != undefined && param[1] != undefined) {//两个都不为空的时候需要在时间之间 d1 = new Date(param[0].replace(/-/g, "/")); d2 = new Date(param[1].replace(/-/g, "/")); return (d1 < d1 < d2); } else if (param[1] != undefined) {//第二个参数不为空,则需要时间小于参数 d2 = new Date(param[1].replace(/-/g, "/")); return (d < d2); } else if (param[0] != undefined) {//第一个参数不为空,则需要时间大于参数 d1 = new Date(param[0].replace(/-/g, "/")); return (d > d1); } return true;*/ }, message: "时间范围选择有误{0}{1}" }, code: { validator: function (value, param) { var reg = new RegExp("<.*?script[^>]*?>.*?(<\/.*?script.*?>)*", "ig"); return !reg.test(value); }, message: "您输入了非法危险字符" } };