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