Skip to content

Commit

Permalink
Fix the isDecimal() validator, closes #419, cc #406
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Aug 4, 2015
1 parent a08ec14 commit 6f83606
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ describe('Validators', function () {
]
});
});

it('should validate decimal numbers', function () {
test({
validator: 'isDecimal'
Expand All @@ -588,6 +588,9 @@ describe('Validators', function () {
, invalid: [
'....'
, ' '
, ''
, '-'
, '+'
, '.'
, '0.1a'
, 'a'
Expand Down
6 changes: 3 additions & 3 deletions validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
, int = /^(?:[-+]?(?:0|[1-9][0-9]*))$/
, float = /^(?:[-+]?(?:[0-9]+))?(?:\.[0-9]*)?(?:[eE][\+\-]?(?:[0-9]+))?$/
, hexadecimal = /^[0-9A-F]+$/i
, decimal = /^[-+]?[0-9]*(\.[0-9]+)?$/
, decimal = /^[-+]?([0-9]+|\.[0-9]+|[0-9]+\.[0-9]+)$/
, hexcolor = /^#?([0-9A-F]{3}|[0-9A-F]{6})$/i;

var ascii = /^[\x00-\x7F]+$/
Expand Down Expand Up @@ -394,9 +394,9 @@
validator.isNumeric = function (str) {
return numeric.test(str);
};

validator.isDecimal = function (str) {
return decimal.test(str);
return str !== '' && decimal.test(str);
};

validator.isHexadecimal = function (str) {
Expand Down
Loading

0 comments on commit 6f83606

Please sign in to comment.