@yoooloo42/bean 1.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/utils/regex.js +25 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yoooloo42/bean",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -112,9 +112,33 @@ function password(str) {
112
112
  return isCombinationValid;
113
113
  }
114
114
 
115
+ /**
116
+ * 验证一个字符串是否符合常见的验证码规则。
117
+ * 规则:长度在 4 到 8 位之间,内容只包含数字和大小写字母。
118
+ * * @param {string} codeStr - 需要验证的字符串。
119
+ * @returns {boolean} - 如果符合规则返回 true,否则返回 false。
120
+ */
121
+ function vercode(str) {
122
+ // 1. 检查输入是否为字符串
123
+ if (typeof str !== 'string') {
124
+ return false;
125
+ }
126
+
127
+ // 2. 正则表达式解释:
128
+ // ^ 表示字符串的开始
129
+ // [0-9a-zA-Z] 表示字符必须是数字(0-9)或大小写字母(a-z, A-Z)
130
+ // {4,8} 表示字符的长度必须在 4 到 8 位之间(包含 4 和 8)
131
+ // $ 表示字符串的结束
132
+ const Regex = /^[0-9a-zA-Z]{4,8}$/;
133
+
134
+ // 3. 执行匹配
135
+ return Regex.test(str);
136
+ }
137
+
115
138
  const bean = {
116
139
  cellphone,
117
140
  email,
118
- password
141
+ password,
142
+ vercode
119
143
  }
120
144
  export default bean