Skip to content

Commit fbf6e91

Browse files
committed
修复中文正则
1 parent 9354bb0 commit fbf6e91

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

src/rules.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ module.exports = {
186186
*/
187187
chinese: {
188188
message: '只能输入中文字符',
189-
rule: /^[\u4e00-\u9fa5]{0,}$/
189+
rule: /^[\u4e00-\u9fa5]+$/
190190
},
191191
/**
192192
* 最少多少个中文字符
@@ -203,7 +203,7 @@ module.exports = {
203203
maxChinese: {
204204
message: '最多输入 {0} 个中文字符',
205205
rule(value, param){
206-
return new RegExp(`^[\u4e00-\u9fa5]{0,${param}}$`).test(value)
206+
return new RegExp(`^[\u4e00-\u9fa5]{1,${param}}$`).test(value)
207207
}
208208
},
209209
/**

src/we-validator.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,21 @@ const isRegExp = (v) => (objString.call(v) === '[object RegExp]')
2020

2121
class WeValidator {
2222

23+
/**
24+
* 默认参数
25+
* @param {object} options
26+
* @param {object} [options.rules] 验证字段的规则
27+
* @param {object} [options.messages] 验证字段错误的提示信息
28+
* @param {function} [options.onMessage] 错误提示显示方式
29+
* @param {boolean} [options.multiCheck] 是否同时校验多个字段
30+
*/
2331
constructor(options = {}) {
24-
this.options = Object.assign({}, WeValidator.defaultOptions, options)
32+
this.options = options
2533

2634
this.required = requiredFn
2735
this._checkAllRules()
2836
}
2937

30-
/**
31-
* 默认参数
32-
* @param {object} rules 验证字段的规则
33-
* @param {object} messages 验证字段错误的提示信息
34-
* @param {function} onMessage 错误提示显示方式
35-
* @param {boolean} multiCheck 是否同时校验多个字段
36-
*/
37-
static defaultOptions = {
38-
rules: {},
39-
messages: {},
40-
onMessage: null,
41-
multiCheck: false
42-
}
43-
4438
/**
4539
* 所有校验规则
4640
*/

0 commit comments

Comments
 (0)