-
Notifications
You must be signed in to change notification settings - Fork 0
/
devops-validation.js
90 lines (86 loc) · 3.15 KB
/
devops-validation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
(function ($) {
$.fn.bootstrapValidator.i18n = $.extend(true, $.fn.bootstrapValidator.i18n, {
safeName: {
'default': 'Please enter a safe String, can not contains ?*/%!@#$^&|<>[]:;'
},
chinese: {
'default': '请输入中文字符'
},
duplicate: {
'default': '重复'
}
});
$.fn.bootstrapValidator.validators = $.extend(true, $.fn.bootstrapValidator.validators, {
safeName: {
enableByHtml5: function ($field) {
var safeName = $field.attr('safeName') + '';
return ('safeName' === safeName || 'true' === safeName);
},
validate: function (validator, $field, options) {
var value = $field.val();
for(var i in value) {
if("?*/\%!@#$^&|<>[]:;".indexOf(value[i]) != -1){
return false;
}
}
return true;
}
},
chinese: {
html5Attributes: {
message: 'message',
language: 'chinese'
},
enableByHtml5: function ($field) {
var language = $field.attr('language') + '';
return ('chinese' === language);
},
validate: function (validator, $field, options) {
var value = $field.val();
return (/^[\u4e00-\u9fa5]*$/.test(value));
}
},
notEmptySelector: {
enableByHtml5: function ($field) {
var notEmptySelector = $field.attr('notEmptySelector') + '';
return ('notEmptySelector' === notEmptySelector || 'true' === notEmptySelector);
},
validate: function (validator, $field, options) {
var val = $field.val();
return val !== '-1' && val !== '';
}
},
duplicate: {
html5Attributes: {
message: 'message'
},
enableByHtml5: function ($field) {
var duplicate = $field.attr('duplicate') + '';
return ('duplicate' === duplicate || 'true' === duplicate);
},
validate: function (validator, $field, options) {
var val = $field.val();
var name = $field.attr('name');
var remote = $field.attr('data-remote');
//var param = $field.attr('data-remove-param');
var message = $field.attr('duplicate-message');
var requestParam = {};
requestParam[name] = val;
var result = true;
$.devopsAjax({
data: requestParam
}).query({
url: remote,
async: false,
success: function (data) {
result = !data.exists;
}
});
return {
valid: result,
message: message || $.fn.bootstrapValidator.i18n.duplicate
};
}
}
});
}(window.jQuery));