Skip to content

Commit

Permalink
修复中文正则
Browse files Browse the repository at this point in the history
  • Loading branch information
ChanceYu committed May 12, 2019
1 parent 9354bb0 commit fbf6e91
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ module.exports = {
*/
chinese: {
message: '只能输入中文字符',
rule: /^[\u4e00-\u9fa5]{0,}$/
rule: /^[\u4e00-\u9fa5]+$/
},
/**
* 最少多少个中文字符
Expand All @@ -203,7 +203,7 @@ module.exports = {
maxChinese: {
message: '最多输入 {0} 个中文字符',
rule(value, param){
return new RegExp(`^[\u4e00-\u9fa5]{0,${param}}$`).test(value)
return new RegExp(`^[\u4e00-\u9fa5]{1,${param}}$`).test(value)
}
},
/**
Expand Down
24 changes: 9 additions & 15 deletions src/we-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,21 @@ const isRegExp = (v) => (objString.call(v) === '[object RegExp]')

class WeValidator {

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

this.required = requiredFn
this._checkAllRules()
}

/**
* 默认参数
* @param {object} rules 验证字段的规则
* @param {object} messages 验证字段错误的提示信息
* @param {function} onMessage 错误提示显示方式
* @param {boolean} multiCheck 是否同时校验多个字段
*/
static defaultOptions = {
rules: {},
messages: {},
onMessage: null,
multiCheck: false
}

/**
* 所有校验规则
*/
Expand Down

0 comments on commit fbf6e91

Please sign in to comment.