Skip to content

Commit

Permalink
fix: check number exclude NaN (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
beliefgp authored and dead-horse committed Nov 23, 2017
1 parent 67d8cf6 commit 3693861
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ function checkInt(rule, value) {
*/

function checkNumber(rule, value) {
if (typeof value !== 'number') {
if (typeof value !== 'number' || isNaN(value)) {
return this.t('should be a number');
}
if (rule.hasOwnProperty('max') && value > rule.max) {
Expand Down
6 changes: 6 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ describe('parameter', function () {
parameter.validate(rule, value)[0].message.should.equal('should be a number');
});

it('should check NaN error', function () {
var value = { number: NaN };
var rule = { number: 'number' };
parameter.validate(rule, value)[0].message.should.equal('should be a number');
});

it('should check max error', function () {
var value = { number: 101 };
var rule = { number: {type: 'number', max: 100, min: 1 }};
Expand Down

0 comments on commit 3693861

Please sign in to comment.