$.extend($.fn.validatebox.defaults.rules, { CHS: { validator: function (value, param) { return /^[\u0391-\uFFE5]+$/.test(value); }, message: '请输入汉字' }, ZIP: { validator: function (value, param) { return /^[1-9]\d{5}$/.test(value); }, message: '邮政编码不存在' }, QQ: { validator: function (value, param) { return /^[1-9]\d{4,10}$/.test(value); }, message: 'QQ号码不正确' }, mobile: { validator: function (value, param) { return /^0?(13[0-9]|15[012356789]|17[0678]|18[0-9]|14[57])[0-9]{8}$/.test(value); }, message: '手机号码不正确' }, 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' }, loginName: { validator: function (value, param) { return /^[\u0391-\uFFE5\w]+$/.test(value); }, message: '登录名称只允许汉字、英文字母、数字及下划线。' }, safepass: { validator: function (value, param) { return safePassword(value); }, message: '密码由字母和数字组成,至少6位' }, /* <input type="password" id="txtpasswd" /> <input type="password" id="txtpasswd2" validType="equalTo['#txtpasswd']" /> */ equalTo: { validator: function (value, param) { return value == $(param[0]).val(); }, message: '两次输入的字符不一至' }, number: { validator: function (value, param) { return /^\d+$/.test(value); }, message: '请输入数字' }, money: { validator: function (value, param) { return /^(([1-9]{1}\d*)|([0]{1}))(\.(\d){1,2})?$/.test(value); }, message: '请输入金额(例:8.88或8)' }, ip: {// 验证IP地址 validator: function (value) { return /d+.d+.d+.d+/i.test(value); }, message: 'IP地址格式不正确' }, idcard: { validator: function (value, param) { return idCard(value); }, message: '请输入正确的身份证号码' }, title: { validator: function (value) { return /^[\u0391-\uFFE5\w]+$/.test(value); }, message: '只允许汉字、英文字母、数字及下划线。' }, messageFormat: { validator: function (value) { return value.indexOf(" ") < 0; }, message: '不能输入特殊字符!' }, dateCompare: { validator: function (value, param) { //var d1 = $.fn.datebox.defaults.parser(param[0]); var d1 = $(param[0]).datetimebox('getValue'); var d2 = value; return d2 >= d1; }, message: '{1}' }, dateCompareLess: { validator: function (value, param) { //var d1 = $.fn.datebox.defaults.parser(param[0]); var d1 = $(param[0]).datetimebox('getValue'); var d2 = value; return d2 <= d1; }, message: '{1}' }, //data-options="validType:['email','isExists[\'EmailIsExists\',\'fdfdfd\']']" 多个调用 //data-options="validType:['isExists[\'EmailIsExists\',\'fdfdfd\']']" 多个调用 isExists: { validator: function (value, param) { if ($.trim(value) == "") { return true; } var result = isExists(param[0], param[2], param[3], value); return result; //if (param) { //this.message.replace("{0}", param[1]+"||"+param[0]); //for (var i = 0; i < param.length; i++) { // this.message = this.message.replace(new RegExp( // "\\{" + i + "\\}", "g"), param[i]); //} //} }, message: '{1}' //{0就是第0个参数,1则为第一个参数} }, comboBoxRequired: { validator: function (value, param) { var isRequired = $("#" + param[0]).attr(param[1]); if (isRequired != 1 && (value == "" || value.indexOf('选择') >= 0 || value.indexOf('全部') >= 0)) { return false; } else { return true; } }, message: '该下拉框为必选项' }, comboBoxEditvalid: { validator: function (value, param) { var $combobox = $("#" + param[0]); if (value) { if ($combobox.combobox('getValue') == $combobox.combobox('getText')) return false; return true; } return false; }, message: '请选择下拉框选项,不要直接使用输入内容' }, //用户账号验证(只能包括 _ 数字 字母) account: {//param的值为[]中值 validator: function (value, param) { if (value.length < param[0] || value.length > param[1]) { $.fn.validatebox.defaults.rules.account.message = '用户名长度必须在' + param[0] + '至' + param[1] + '范围'; return false; } else { if (!/^[\w]+$/.test(value)) { $.fn.validatebox.defaults.rules.account.message = '用户名只能数字、字母、下划线组成.'; return false; } else { return true; } } }, message: '' } });
<input name="CatelogParentId" id="CatelogParentId" class="easyui-combobox" type="text" data-options="required:true,validType:'comboBoxEditvalid[\'CatelogParentId\']'" >
Easyui.initCombobox = function (options) { var $combobox = $("#" + options.id); var _options = $.extend({ valueField: 'id', textField: 'text', validType: 'comboBoxEditvalid[\'' + options.id + '\',\'isRequired\']', url: encodeURIComponent(options.url) }, options); $combobox.combobox(_options); };
@model Rednoble.OMS.CMS.Infastracture.Until.CustomCombobox <input id="@Model.Id" name="@Model.Name" class="easyui-combobox" data-options="required:true,validType:['comboBoxRequired[\'@(Model.Id)\',\'isRequired\']','comboBoxEditvalid[\'@(Model.Id)\']'],editable:@Model.Editable.ToString().ToLower()" /> <script type="text/javascript"> $(document).ready(function () { Easyui.initCombobox({ url: "@(Model.Url+Model.SpitStr)Text=" + escape("@Model.Text"), id: "@Model.Id", onLoadSuccess: function() { if ("@Model.IsRequest" == "false" || "@Model.IsRequest" == "False") { //取消必填 $("#" + "@Model.Id").attr("isRequired", "1").parent().find(".validatebox-invalid").removeClass("validatebox-invalid"); } if ('@Model.Value') { $("#" + "@Model.Id").combobox('setValue', '@Model.Value'); } } }); }); function toBool(str) { if (str == 'True' || str == 'true' || str == '1') return true; return false; } </script>