]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - Plugson/www/static/js/jquery.validate.vtoymethods.js
Fix the egrep warning. (#2083)
[Ventoy.git] / Plugson / www / static / js / jquery.validate.vtoymethods.js
1 function ventoy_check_file_name_char(path) {
2 for (var i = 0; i < path.length; i++) {
3 var cc = path[i];
4 if (cc === '/' || cc === '\\' || cc === '*' || cc === '?' || cc === '"' || cc === '<' || cc === '>' || cc === '|')
5 {
6 return false;
7 }
8 }
9
10 return true;
11 }
12
13
14 (function(factory) {
15 if (typeof define === "function" && define.amd) {
16 define(["jquery", "../jquery.validate"], factory);
17 } else {
18 factory(jQuery);
19 }
20 } (function($) {
21
22 // 设置validator插件默认校验格式
23 $.validator.setDefaults({
24 highlight: function(element) {
25 $(element).closest('.form-group').addClass('has-error');
26 },
27 success: function(label) {
28 label.closest('.form-group').removeClass('has-error');
29 label.remove();
30 }
31 });
32
33
34 //密码
35 $.validator.addMethod('password', function(value, element, params) {
36 if (this.optional(element)) {
37 return true;
38 }
39 var re = /^[^\u4e00-\u9fa5]{1,64}$/;
40 return re.test(value);
41 }, '密码不合法');
42
43 $.validator.addMethod('utfmaxlen', function(value, element, params) {
44 if (this.optional(element)) {
45 return true;
46 }
47
48 if (ventoy_get_ulen(value) > 250) {
49 return false;
50 }
51
52 return true;
53 }, 'Input too long');
54
55 $.validator.addMethod('start_slash', function(value, element, params) {
56 if (this.optional(element)) {
57 return true;
58 }
59
60 if (value.length > 0 && value.charCodeAt(0) != 47) {
61 return false;
62 }
63
64 return true;
65 }, 'Must start with /');
66
67 $.validator.addMethod('noquotes', function(value, element, params) {
68 if (this.optional(element)) {
69 return true;
70 }
71
72 if (value.length > 0 && value.indexOf('"') >= 0) {
73 return false;
74 }
75
76 return true;
77 }, 'Can not contain double quotes');
78
79 $.validator.addMethod('filenamepart', function(value, element, params) {
80 if (this.optional(element)) {
81 return true;
82 }
83
84 return ventoy_check_file_name_char(value);
85 }, 'Invalid characters');
86
87
88 $.validator.addMethod('printascii', function(value, element, params) {
89 if (this.optional(element)) {
90 return true;
91 }
92
93 for (var i = 0; i < value.length; i++) {
94 if (value.charCodeAt(i) > 127) {
95 return false;
96 }
97 }
98
99 if (value.length > 0 && value.indexOf('"') >= 0) {
100 return false;
101 }
102
103 return true;
104 }, 'Can only use printable ascii code');
105
106 }));