Skip to content

Commit

Permalink
fix: 修复 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ChanceYu committed Sep 5, 2021
1 parent 6ddd062 commit 683c81c
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 30 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
## Released


### [v2.1.16](https://github.com/ChanceYu/we-validator/releases/tag/v2.1.16)
- 修复:错误 message 的显示优化[pull](https://github.com/ChanceYu/we-validator/pull/16)
- 修复:修改空指针和语法修改[pull](https://github.com/ChanceYu/we-validator/pull/17)
- 修复:required: false 不进行“必须”验证[pull](https://github.com/ChanceYu/we-validator/pull/18)


### [v2.1.15](https://github.com/ChanceYu/we-validator/releases/tag/v2.1.15)
- 修复:部分ts定义错误[issue](https://github.com/ChanceYu/we-validator/issues/15)

Expand Down
20 changes: 11 additions & 9 deletions dist/we-validator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* we-validator
* version: 2.1.15
* version: 2.1.16
* address: https://github.com/ChanceYu/we-validator#readme
* author: ChanceYu <i.fish@foxmail.com>
* license: MIT
Expand Down Expand Up @@ -238,7 +238,7 @@ var WeValidator = function () {
var messages = this.options.messages;
var defaultMessage = WeValidator.RULES[ruleName].message;

if (messages.hasOwnProperty(attr) && messages[attr][ruleName]) {
if (messages && messages.hasOwnProperty(attr) && messages[attr][ruleName]) {
defaultMessage = messages[attr][ruleName];
}

Expand Down Expand Up @@ -354,7 +354,9 @@ var WeValidator = function () {
}

if (!multiCheck) {
errorParam && this._showErrorMessage(errorParam, onMessage);
if (errorParam) {
this._showErrorMessage(errorParam, onMessage);
}
return false;
}
}
Expand Down Expand Up @@ -484,7 +486,7 @@ WeValidator.checkValue = function (ruleName, value, param, skip) {

if (isFunction(rule)) {
if (ruleName === 'required') {
return requiredFn(value);
return param && requiredFn(value);
} else {
if (skip) {
return !requiredFn(value) || rule.call(this, value, param);
Expand Down Expand Up @@ -542,7 +544,7 @@ module.exports = {
* 手机号码
*/
mobile: {
message: '请输入11位的手机号码',
message: '请输入 11 位的手机号码',
rule: /^1[3456789]\d{9}$/
},
/**
Expand All @@ -563,7 +565,7 @@ module.exports = {
* 身份证号
*/
idcard: {
message: '请输入18位的有效身份证',
message: '请输入 18 位的有效身份证',
rule: /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/
},
/**
Expand Down Expand Up @@ -737,21 +739,21 @@ module.exports = {
* 日期(ISO标准格式)例如:2019-09-19,2019/09/19
*/
dateISO: {
message: '请输入有效的日期(ISO标准格式)',
message: '请输入有效的日期(ISO 标准格式)',
rule: /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/
},
/**
* ipv4地址
*/
ipv4: {
message: '请输入有效的IPv4地址',
message: '请输入有效的 IPv4 地址',
rule: /^(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)$/i
},
/**
* ipv6地址
*/
ipv6: {
message: '请输入有效的IPv6地址',
message: '请输入有效的 IPv6 地址',
rule: /^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/i
}
};
Expand Down
4 changes: 2 additions & 2 deletions dist/we-validator.min.js

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions example/wechat/js/we-validator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* we-validator
* version: 2.1.15
* version: 2.1.16
* address: https://github.com/ChanceYu/we-validator#readme
* author: ChanceYu <i.fish@foxmail.com>
* license: MIT
Expand Down Expand Up @@ -238,7 +238,7 @@ var WeValidator = function () {
var messages = this.options.messages;
var defaultMessage = WeValidator.RULES[ruleName].message;

if (messages.hasOwnProperty(attr) && messages[attr][ruleName]) {
if (messages && messages.hasOwnProperty(attr) && messages[attr][ruleName]) {
defaultMessage = messages[attr][ruleName];
}

Expand Down Expand Up @@ -354,7 +354,9 @@ var WeValidator = function () {
}

if (!multiCheck) {
errorParam && this._showErrorMessage(errorParam, onMessage);
if (errorParam) {
this._showErrorMessage(errorParam, onMessage);
}
return false;
}
}
Expand Down Expand Up @@ -484,7 +486,7 @@ WeValidator.checkValue = function (ruleName, value, param, skip) {

if (isFunction(rule)) {
if (ruleName === 'required') {
return requiredFn(value);
return param && requiredFn(value);
} else {
if (skip) {
return !requiredFn(value) || rule.call(this, value, param);
Expand Down Expand Up @@ -542,7 +544,7 @@ module.exports = {
* 手机号码
*/
mobile: {
message: '请输入11位的手机号码',
message: '请输入 11 位的手机号码',
rule: /^1[3456789]\d{9}$/
},
/**
Expand All @@ -563,7 +565,7 @@ module.exports = {
* 身份证号
*/
idcard: {
message: '请输入18位的有效身份证',
message: '请输入 18 位的有效身份证',
rule: /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/
},
/**
Expand Down Expand Up @@ -737,21 +739,21 @@ module.exports = {
* 日期(ISO标准格式)例如:2019-09-19,2019/09/19
*/
dateISO: {
message: '请输入有效的日期(ISO标准格式)',
message: '请输入有效的日期(ISO 标准格式)',
rule: /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/
},
/**
* ipv4地址
*/
ipv4: {
message: '请输入有效的IPv4地址',
message: '请输入有效的 IPv4 地址',
rule: /^(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)$/i
},
/**
* ipv6地址
*/
ipv6: {
message: '请输入有效的IPv6地址',
message: '请输入有效的 IPv6 地址',
rule: /^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/i
}
};
Expand Down
20 changes: 11 additions & 9 deletions lib/we-validator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* we-validator
* version: 2.1.15
* version: 2.1.16
* address: https://github.com/ChanceYu/we-validator#readme
* author: ChanceYu <i.fish@foxmail.com>
* license: MIT
Expand Down Expand Up @@ -238,7 +238,7 @@ var WeValidator = function () {
var messages = this.options.messages;
var defaultMessage = WeValidator.RULES[ruleName].message;

if (messages.hasOwnProperty(attr) && messages[attr][ruleName]) {
if (messages && messages.hasOwnProperty(attr) && messages[attr][ruleName]) {
defaultMessage = messages[attr][ruleName];
}

Expand Down Expand Up @@ -354,7 +354,9 @@ var WeValidator = function () {
}

if (!multiCheck) {
errorParam && this._showErrorMessage(errorParam, onMessage);
if (errorParam) {
this._showErrorMessage(errorParam, onMessage);
}
return false;
}
}
Expand Down Expand Up @@ -484,7 +486,7 @@ WeValidator.checkValue = function (ruleName, value, param, skip) {

if (isFunction(rule)) {
if (ruleName === 'required') {
return requiredFn(value);
return param && requiredFn(value);
} else {
if (skip) {
return !requiredFn(value) || rule.call(this, value, param);
Expand Down Expand Up @@ -542,7 +544,7 @@ module.exports = {
* 手机号码
*/
mobile: {
message: '请输入11位的手机号码',
message: '请输入 11 位的手机号码',
rule: /^1[3456789]\d{9}$/
},
/**
Expand All @@ -563,7 +565,7 @@ module.exports = {
* 身份证号
*/
idcard: {
message: '请输入18位的有效身份证',
message: '请输入 18 位的有效身份证',
rule: /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/
},
/**
Expand Down Expand Up @@ -737,21 +739,21 @@ module.exports = {
* 日期(ISO标准格式)例如:2019-09-19,2019/09/19
*/
dateISO: {
message: '请输入有效的日期(ISO标准格式)',
message: '请输入有效的日期(ISO 标准格式)',
rule: /^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$/
},
/**
* ipv4地址
*/
ipv4: {
message: '请输入有效的IPv4地址',
message: '请输入有效的 IPv4 地址',
rule: /^(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)\.(25[0-5]|2[0-4]\d|[01]?\d\d?)$/i
},
/**
* ipv6地址
*/
ipv6: {
message: '请输入有效的IPv6地址',
message: '请输入有效的 IPv6 地址',
rule: /^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/i
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/we-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class WeValidator {

if(isFunction(rule)){
if(ruleName === 'required'){
return requiredFn(value)
return param && requiredFn(value)
}else{
if(skip){
return !requiredFn(value) || rule.call(this, value, param)
Expand Down

0 comments on commit 683c81c

Please sign in to comment.