Easyuiは拡張を検証して、compboxを制限してオプションの内容を入力することしかできません.
24532 ワード
$.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 '
},
/*
*/
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: ''
}
});
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
"@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()" />
"</span><span style="color:#800000;">text/javascript</span><span style="color:#800000;">"</span>><span style="color:#000000;">
$(document).ready(function () {
Easyui.initCombobox({
url: </span><span style="color:#800000;">"</span><span style="color:#800000;">@(Model.Url+Model.SpitStr)Text=</span><span style="color:#800000;">"</span> + escape(<span style="color:#800000;">"</span><span style="color:#800000;">@Model.Text</span><span style="color:#800000;">"</span><span style="color:#000000;">),
id: </span><span style="color:#800000;">"</span><span style="color:#800000;">@Model.Id</span><span style="color:#800000;">"</span><span style="color:#000000;">,
onLoadSuccess: function() {
</span><span style="color:#0000ff;">if</span> (<span style="color:#800000;">"</span><span style="color:#800000;">@Model.IsRequest</span><span style="color:#800000;">"</span> == <span style="color:#800000;">"</span><span style="color:#800000;">false</span><span style="color:#800000;">"</span> || <span style="color:#800000;">"</span><span style="color:#800000;">@Model.IsRequest</span><span style="color:#800000;">"</span> == <span style="color:#800000;">"</span><span style="color:#800000;">False</span><span style="color:#800000;">"</span><span style="color:#000000;">) {
</span><span style="color:#008000;">//</span><span style="color:#008000;"> </span>
$(<span style="color:#800000;">"</span><span style="color:#800000;">#</span><span style="color:#800000;">"</span> + <span style="color:#800000;">"</span><span style="color:#800000;">@Model.Id</span><span style="color:#800000;">"</span>).attr(<span style="color:#800000;">"</span><span style="color:#800000;">isRequired</span><span style="color:#800000;">"</span>, <span style="color:#800000;">"</span><span style="color:#800000;">1</span><span style="color:#800000;">"</span>).parent().find(<span style="color:#800000;">"</span><span style="color:#800000;">.validatebox-invalid</span><span style="color:#800000;">"</span>).removeClass(<span style="color:#800000;">"</span><span style="color:#800000;">validatebox-invalid</span><span style="color:#800000;">"</span><span style="color:#000000;">);
}
</span><span style="color:#0000ff;">if</span> (<span style="color:#800000;">'</span><span style="color:#800000;">@Model.Value</span><span style="color:#800000;">'</span><span style="color:#000000;">) {
$(</span><span style="color:#800000;">"</span><span style="color:#800000;">#</span><span style="color:#800000;">"</span> + <span style="color:#800000;">"</span><span style="color:#800000;">@Model.Id</span><span style="color:#800000;">"</span>).combobox(<span style="color:#800000;">'</span><span style="color:#800000;">setValue</span><span style="color:#800000;">'</span>, <span style="color:#800000;">'</span><span style="color:#800000;">@Model.Value</span><span style="color:#800000;">'</span><span style="color:#000000;">);
}
}
});
});
function toBool(str) {
</span><span style="color:#0000ff;">if</span> (str == <span style="color:#800000;">'</span><span style="color:#800000;">True</span><span style="color:#800000;">'</span> || str == <span style="color:#800000;">'</span><span style="color:#800000;">true</span><span style="color:#800000;">'</span> || str == <span style="color:#800000;">'</span><span style="color:#800000;">1</span><span style="color:#800000;">'</span><span style="color:#000000;">)
</span><span style="color:#0000ff;">return</span> <span style="color:#0000ff;">true</span><span style="color:#000000;">;
</span><span style="color:#0000ff;">return</span> <span style="color:#0000ff;">false</span><span style="color:#000000;">;
}
</span>
転載先:https://www.cnblogs.com/871735097-/p/4988334.html