Skip to content

Commit

Permalink
Fix isFloat('.') === true, closes #443
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Oct 20, 2015
1 parent 825af6a commit 902cfc9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#### HEAD

- Fix the incorrect `isFloat('.') === true`
([#443](https://github.com/chriso/validator.js/pull/443))
- Added a Norwegian locale to `isMobilePhone()`
([#439](https://github.com/chriso/validator.js/pull/439))

Expand Down
1 change: 1 addition & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ describe('Validators', function () {
'-.123'
, ' '
, ''
, '.'
, 'foo'
]
});
Expand Down
5 changes: 4 additions & 1 deletion validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,10 @@

validator.isFloat = function (str, options) {
options = options || {};
return str !== '' && float.test(str) && (!options.hasOwnProperty('min') || str >= options.min) && (!options.hasOwnProperty('max') || str <= options.max);
if (str === '' || str === '.') {
return false;
}
return float.test(str) && (!options.hasOwnProperty('min') || str >= options.min) && (!options.hasOwnProperty('max') || str <= options.max);
};

validator.isDivisibleBy = function (str, num) {
Expand Down
Loading

0 comments on commit 902cfc9

Please sign in to comment.