ztxkutils 2.10.41 → 2.10.43
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.js +1 -1
- package/dist/validate-2081dd82.js +161 -0
- package/dist/validate-e3483c15.js +196 -0
- package/dist/validate.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
export { c as authority } from './authority-e6bde99f.js';
|
2
2
|
export { d as dataModel } from './dataModel-1fbaff40.js';
|
3
3
|
export { t as tools } from './tools-09a4d620.js';
|
4
|
-
export { v as validate } from './validate-
|
4
|
+
export { v as validate } from './validate-e3483c15.js';
|
5
5
|
export { r as request } from './request-ba8abf99.js';
|
6
6
|
export { r as reqUrl } from './reqUrl-787dd9e5.js';
|
7
7
|
import './tslib.es6-35653116.js';
|
@@ -0,0 +1,161 @@
|
|
1
|
+
/**
|
2
|
+
* @description 常用正则表达式
|
3
|
+
*/
|
4
|
+
var validate = {
|
5
|
+
/**
|
6
|
+
* @description 长度验证,最小长度字符,0-200个字符
|
7
|
+
*/
|
8
|
+
smallLenValidate: /^(?:\s*)[\s\S]{0,200}(?:\s*)$/,
|
9
|
+
/**
|
10
|
+
* @description 长度验证,中等长度字符,0-400个字符
|
11
|
+
*/
|
12
|
+
middleLenValidate: /^(?:\s*)[\s\S]{0,400}(?:\s*)$/,
|
13
|
+
/**
|
14
|
+
* @description 长度验证,最大长度字符,0-600个字符
|
15
|
+
*/
|
16
|
+
largeLenValidate: /^(?:\s*)[\s\S]{0,600}(?:\s*)$/,
|
17
|
+
/**
|
18
|
+
* @description 长度验证,最大长度字符,0-5000个字符
|
19
|
+
*/
|
20
|
+
maxlargeLenValidate: /^(?:\s*)[\s\S]{0,5000}(?:\s*)$/,
|
21
|
+
/**
|
22
|
+
* @description 电话号码验证
|
23
|
+
*/
|
24
|
+
// phoneValidate: /^1(3\d|4\d|5\d|6\d|7\d|8\d|9\d)\d{8}$/,
|
25
|
+
// 数字 横线 长度 0 - 15位/^([0-9])|(\-)*$/
|
26
|
+
phoneValidate: /^[0-9\-]{0,15}$/,
|
27
|
+
/**
|
28
|
+
* @description 短信验证码 接受11位手机号
|
29
|
+
*/
|
30
|
+
shortPhoneValidate: /^1[0-9]{10}$/,
|
31
|
+
/**
|
32
|
+
* @description 身份证验证
|
33
|
+
* 18位 最后一位可以是X x
|
34
|
+
*/
|
35
|
+
idCardValidate: /^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
|
36
|
+
/**
|
37
|
+
* @description 邮箱验证
|
38
|
+
*/
|
39
|
+
emailValidate: /^([\s\S])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,8})$/,
|
40
|
+
/**
|
41
|
+
* @description 密码验证
|
42
|
+
*/
|
43
|
+
// passwordValidate: /^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)])+$)^.{8,16}$/,
|
44
|
+
passwordValidate: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\da-zA-Z]).{8,}$/,
|
45
|
+
/**
|
46
|
+
* @description 空格验证
|
47
|
+
*/
|
48
|
+
spaceValidate: /^[^\s]*$/g,
|
49
|
+
};
|
50
|
+
var commonMessage = {
|
51
|
+
smallLenMessage: function (type) {
|
52
|
+
if (type === void 0) { type = ''; }
|
53
|
+
return type + "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA6200";
|
54
|
+
},
|
55
|
+
middleLenMessage: function (type) {
|
56
|
+
if (type === void 0) { type = ''; }
|
57
|
+
return type + "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA6400";
|
58
|
+
},
|
59
|
+
largeLenMessage: function (type) {
|
60
|
+
if (type === void 0) { type = ''; }
|
61
|
+
return type + "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA6600";
|
62
|
+
},
|
63
|
+
maxlargeLenValidate: function (type) {
|
64
|
+
if (type === void 0) { type = ''; }
|
65
|
+
return type + "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA65000";
|
66
|
+
},
|
67
|
+
phoneMessage: '请输入正确的手机号',
|
68
|
+
idCardMessage: '请输入正确的身份证',
|
69
|
+
emailMessage: '请输入正确的邮箱',
|
70
|
+
// passwordMessage: '密码由8-16位的字母+数字,字母+特殊字符,数字+特殊字符组成',
|
71
|
+
passwordMessage: '密码必须包含大小写字母、数字、特殊字符且最小长度为8,且不能出现连续数字或字符,不能出现相同字符,且禁止使用用户账号作为密码',
|
72
|
+
spaceMessage: '请勿输入空格',
|
73
|
+
};
|
74
|
+
function isConsecutiveChars(char1, char2) {
|
75
|
+
var lowerCaseAlphabet = 'abcdefghijklmnopqrstuvwxyz'; // 小写字母
|
76
|
+
var upperCaseAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; // 大写字母
|
77
|
+
var numeric = '0123456789'; // 数字
|
78
|
+
// 找到包含两个字符的字符集
|
79
|
+
var alphabet = [lowerCaseAlphabet, upperCaseAlphabet, numeric].find(function (alph) { return alph.includes(char1) && alph.includes(char2); });
|
80
|
+
if (!alphabet) {
|
81
|
+
return false; // 如果两个字符不在同一字符集中,那么它们不可能连续
|
82
|
+
}
|
83
|
+
var index1 = alphabet.indexOf(char1);
|
84
|
+
var index2 = alphabet.indexOf(char2);
|
85
|
+
return Math.abs(index1 - index2) === 1; // 如果两个字符在字符集中的位置相邻,那么它们是连续的
|
86
|
+
}
|
87
|
+
function validatePassword(password, username) {
|
88
|
+
// 用正则表达式检查密码基本规则
|
89
|
+
var regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\da-zA-Z]).{8,}$/;
|
90
|
+
if (!regex.test(password)) {
|
91
|
+
return {
|
92
|
+
result: false,
|
93
|
+
message: '密码中必须包含大小写字母、数字、特殊字符,且长度必须大于8个字符!',
|
94
|
+
};
|
95
|
+
}
|
96
|
+
// 检查密码中是否有连续的字母或数字 连续超过三次
|
97
|
+
var count = 0;
|
98
|
+
var startChart = 0;
|
99
|
+
for (var i = 0; i < password.length - 1; i++) {
|
100
|
+
if (isConsecutiveChars(password[i], password[i + 1])) {
|
101
|
+
if (count === 0) {
|
102
|
+
startChart = i;
|
103
|
+
}
|
104
|
+
count++;
|
105
|
+
if (count >= 2) {
|
106
|
+
// 密码中不应含有连续的字母或数字
|
107
|
+
return {
|
108
|
+
result: false,
|
109
|
+
message: "\u4ECE\u7B2C" + (startChart + 1) + "\u4E2A\u5B57\u7B26\u5F00\u59CB\uFF0C\u6709\u8FDE\u7EED\u8D85\u8FC7\u4E09\u4F4D\u7684\u5B57\u6BCD\u6216\u6570\u5B57!",
|
110
|
+
};
|
111
|
+
}
|
112
|
+
}
|
113
|
+
else {
|
114
|
+
count = 0;
|
115
|
+
startChart = 0;
|
116
|
+
}
|
117
|
+
}
|
118
|
+
// 检查密码中是否有相同且连续的字符 超过三次
|
119
|
+
var count1 = 0;
|
120
|
+
for (var i = 0; i < password.length - 1; i++) {
|
121
|
+
if (password[i] === password[i + 1]) {
|
122
|
+
count1++;
|
123
|
+
if (count1 >= 2) {
|
124
|
+
return {
|
125
|
+
result: false,
|
126
|
+
message: '密码中有相同且连续超过三次的字符!',
|
127
|
+
};
|
128
|
+
}
|
129
|
+
}
|
130
|
+
else {
|
131
|
+
count1 = 0;
|
132
|
+
}
|
133
|
+
}
|
134
|
+
// const uniqueChars = new Set(password.split(''));
|
135
|
+
// if (uniqueChars.size !== password.length) {
|
136
|
+
// return {
|
137
|
+
// result: false,
|
138
|
+
// message: '密码中有相同的字符!',
|
139
|
+
// };
|
140
|
+
// }
|
141
|
+
// 检查密码是否与用户名相同
|
142
|
+
if (password === username) {
|
143
|
+
return {
|
144
|
+
result: false,
|
145
|
+
message: '密码与用户名相同!',
|
146
|
+
};
|
147
|
+
}
|
148
|
+
// 如果通过了所有的检查,则返回true
|
149
|
+
return {
|
150
|
+
result: true,
|
151
|
+
};
|
152
|
+
}
|
153
|
+
|
154
|
+
var validate$1 = /*#__PURE__*/Object.freeze({
|
155
|
+
__proto__: null,
|
156
|
+
validatePassword: validatePassword,
|
157
|
+
validate: validate,
|
158
|
+
commonMessage: commonMessage
|
159
|
+
});
|
160
|
+
|
161
|
+
export { validatePassword as a, validate as b, commonMessage as c, validate$1 as v };
|
@@ -0,0 +1,196 @@
|
|
1
|
+
/**
|
2
|
+
* @description 常用正则表达式
|
3
|
+
*/
|
4
|
+
var validate = {
|
5
|
+
/**
|
6
|
+
* @description 长度验证,最小长度字符,0-200个字符
|
7
|
+
*/
|
8
|
+
smallLenValidate: /^(?:\s*)[\s\S]{0,200}(?:\s*)$/,
|
9
|
+
/**
|
10
|
+
* @description 长度验证,中等长度字符,0-400个字符
|
11
|
+
*/
|
12
|
+
middleLenValidate: /^(?:\s*)[\s\S]{0,400}(?:\s*)$/,
|
13
|
+
/**
|
14
|
+
* @description 长度验证,最大长度字符,0-600个字符
|
15
|
+
*/
|
16
|
+
largeLenValidate: /^(?:\s*)[\s\S]{0,600}(?:\s*)$/,
|
17
|
+
/**
|
18
|
+
* @description 长度验证,最大长度字符,0-5000个字符
|
19
|
+
*/
|
20
|
+
maxlargeLenValidate: /^(?:\s*)[\s\S]{0,5000}(?:\s*)$/,
|
21
|
+
/**
|
22
|
+
* @description 电话号码验证
|
23
|
+
*/
|
24
|
+
// phoneValidate: /^1(3\d|4\d|5\d|6\d|7\d|8\d|9\d)\d{8}$/,
|
25
|
+
// 数字 横线 长度 0 - 15位/^([0-9])|(\-)*$/
|
26
|
+
phoneValidate: /^[0-9\-]{0,15}$/,
|
27
|
+
/**
|
28
|
+
* @description 短信验证码 接受11位手机号
|
29
|
+
*/
|
30
|
+
shortPhoneValidate: /^1[0-9]{10}$/,
|
31
|
+
/**
|
32
|
+
* @description 身份证验证
|
33
|
+
* 18位 最后一位可以是X x
|
34
|
+
*/
|
35
|
+
idCardValidate: /^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
|
36
|
+
/**
|
37
|
+
* @description 邮箱验证
|
38
|
+
*/
|
39
|
+
emailValidate: /^([\s\S])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,8})$/,
|
40
|
+
/**
|
41
|
+
* @description 密码验证
|
42
|
+
*/
|
43
|
+
// passwordValidate: /^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)])+$)^.{8,16}$/,
|
44
|
+
passwordValidate: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\da-zA-Z]).{8,}$/,
|
45
|
+
/**
|
46
|
+
* @description 空格验证
|
47
|
+
*/
|
48
|
+
spaceValidate: /^[^\s]*$/g,
|
49
|
+
};
|
50
|
+
var commonMessage = {
|
51
|
+
smallLenMessage: function (type) {
|
52
|
+
if (type === void 0) { type = ''; }
|
53
|
+
return type + "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA6200";
|
54
|
+
},
|
55
|
+
middleLenMessage: function (type) {
|
56
|
+
if (type === void 0) { type = ''; }
|
57
|
+
return type + "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA6400";
|
58
|
+
},
|
59
|
+
largeLenMessage: function (type) {
|
60
|
+
if (type === void 0) { type = ''; }
|
61
|
+
return type + "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA6600";
|
62
|
+
},
|
63
|
+
maxlargeLenValidate: function (type) {
|
64
|
+
if (type === void 0) { type = ''; }
|
65
|
+
return type + "\u8D85\u8FC7\u6700\u5927\u5B57\u7B26\u957F\u5EA65000";
|
66
|
+
},
|
67
|
+
phoneMessage: '请输入正确的手机号',
|
68
|
+
idCardMessage: '请输入正确的身份证',
|
69
|
+
emailMessage: '请输入正确的邮箱',
|
70
|
+
// passwordMessage: '密码由8-16位的字母+数字,字母+特殊字符,数字+特殊字符组成',
|
71
|
+
passwordMessage: '密码必须包含大小写字母、数字、特殊字符且最小长度为8,且不能出现连续数字或字符,不能出现相同字符,且禁止使用用户账号作为密码',
|
72
|
+
spaceMessage: '请勿输入空格',
|
73
|
+
};
|
74
|
+
function isConsecutiveChars(char1, char2) {
|
75
|
+
var lowerCaseAlphabet = 'abcdefghijklmnopqrstuvwxyz'; // 小写字母
|
76
|
+
var upperCaseAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; // 大写字母
|
77
|
+
var numeric = '0123456789'; // 数字
|
78
|
+
// 找到包含两个字符的字符集
|
79
|
+
var alphabet = [lowerCaseAlphabet, upperCaseAlphabet, numeric].find(function (alph) { return alph.includes(char1) && alph.includes(char2); });
|
80
|
+
if (!alphabet) {
|
81
|
+
return false; // 如果两个字符不在同一字符集中,那么它们不可能连续
|
82
|
+
}
|
83
|
+
var index1 = alphabet.indexOf(char1);
|
84
|
+
var index2 = alphabet.indexOf(char2);
|
85
|
+
// return Math.abs(index1 - index2) === 1; // 如果两个字符在字符集中的位置相邻,那么它们是连续的
|
86
|
+
return index1 - index2;
|
87
|
+
}
|
88
|
+
function validatePassword(password, username) {
|
89
|
+
// 用正则表达式检查密码基本规则
|
90
|
+
var regex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\da-zA-Z]).{8,}$/;
|
91
|
+
if (!regex.test(password)) {
|
92
|
+
return {
|
93
|
+
result: false,
|
94
|
+
message: '密码中必须包含大小写字母、数字、特殊字符,且长度必须大于8个字符!',
|
95
|
+
};
|
96
|
+
}
|
97
|
+
// 检查密码中是否有连续的字母或数字 连续超过三次
|
98
|
+
var count = 0;
|
99
|
+
var startChart = 0;
|
100
|
+
var currentConsecutiveCount = 0; // 记录上次是递增还是递减
|
101
|
+
for (var i = 0; i < password.length - 1; i++) {
|
102
|
+
var consecutiveCount = isConsecutiveChars(password[i], password[i + 1]);
|
103
|
+
// 是递增 还是 递减
|
104
|
+
if (consecutiveCount === 1 || consecutiveCount === -1) {
|
105
|
+
if (currentConsecutiveCount === 0) {
|
106
|
+
currentConsecutiveCount = consecutiveCount;
|
107
|
+
}
|
108
|
+
if (count === 0) {
|
109
|
+
startChart = i;
|
110
|
+
}
|
111
|
+
// 如果记录到上次跟本次的连续规则相同
|
112
|
+
if (currentConsecutiveCount === consecutiveCount) {
|
113
|
+
count++;
|
114
|
+
if (count >= 2) {
|
115
|
+
// 密码中不应含有连续的字母或数字
|
116
|
+
return {
|
117
|
+
result: false,
|
118
|
+
message: "\u4ECE\u7B2C" + (startChart + 1) + "\u4E2A\u5B57\u7B26\u5F00\u59CB\uFF0C\u6709\u8FDE\u7EED" + (currentConsecutiveCount === 1 ? '递减' : '递增') + "\u8D85\u8FC7\u4E09\u4F4D\u7684\u5B57\u6BCD\u6216\u6570\u5B57!",
|
119
|
+
};
|
120
|
+
}
|
121
|
+
}
|
122
|
+
else {
|
123
|
+
// 需要重置规则
|
124
|
+
count = 0;
|
125
|
+
startChart = 0;
|
126
|
+
}
|
127
|
+
currentConsecutiveCount = consecutiveCount;
|
128
|
+
}
|
129
|
+
else {
|
130
|
+
count = 0;
|
131
|
+
startChart = 0;
|
132
|
+
currentConsecutiveCount = 0;
|
133
|
+
}
|
134
|
+
// if (isConsecutiveChars(password[i], password[i + 1])) {
|
135
|
+
// if (count === 0) {
|
136
|
+
// startChart = i;
|
137
|
+
// }
|
138
|
+
// count++;
|
139
|
+
// if (count >= 2) {
|
140
|
+
// // 密码中不应含有连续的字母或数字
|
141
|
+
// return {
|
142
|
+
// result: false,
|
143
|
+
// message: `从第${
|
144
|
+
// startChart + 1
|
145
|
+
// }个字符开始,有连续超过三位的字母或数字!`,
|
146
|
+
// };
|
147
|
+
// }
|
148
|
+
// } else {
|
149
|
+
// count = 0;
|
150
|
+
// startChart = 0;
|
151
|
+
// }
|
152
|
+
}
|
153
|
+
// 检查密码中是否有相同且连续的字符 超过三次
|
154
|
+
var count1 = 0;
|
155
|
+
for (var i = 0; i < password.length - 1; i++) {
|
156
|
+
if (password[i] === password[i + 1]) {
|
157
|
+
count1++;
|
158
|
+
if (count1 >= 2) {
|
159
|
+
return {
|
160
|
+
result: false,
|
161
|
+
message: '密码中有相同且连续超过三次的字符!',
|
162
|
+
};
|
163
|
+
}
|
164
|
+
}
|
165
|
+
else {
|
166
|
+
count1 = 0;
|
167
|
+
}
|
168
|
+
}
|
169
|
+
// const uniqueChars = new Set(password.split(''));
|
170
|
+
// if (uniqueChars.size !== password.length) {
|
171
|
+
// return {
|
172
|
+
// result: false,
|
173
|
+
// message: '密码中有相同的字符!',
|
174
|
+
// };
|
175
|
+
// }
|
176
|
+
// 检查密码是否与用户名相同
|
177
|
+
if (password === username) {
|
178
|
+
return {
|
179
|
+
result: false,
|
180
|
+
message: '密码与用户名相同!',
|
181
|
+
};
|
182
|
+
}
|
183
|
+
// 如果通过了所有的检查,则返回true
|
184
|
+
return {
|
185
|
+
result: true,
|
186
|
+
};
|
187
|
+
}
|
188
|
+
|
189
|
+
var validate$1 = /*#__PURE__*/Object.freeze({
|
190
|
+
__proto__: null,
|
191
|
+
validatePassword: validatePassword,
|
192
|
+
validate: validate,
|
193
|
+
commonMessage: commonMessage
|
194
|
+
});
|
195
|
+
|
196
|
+
export { validatePassword as a, validate as b, commonMessage as c, validate$1 as v };
|
package/dist/validate.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export { c as commonMessage, b as validate, a as validatePassword } from './validate-
|
1
|
+
export { c as commonMessage, b as validate, a as validatePassword } from './validate-e3483c15.js';
|