Skip to content

Commit

Permalink
Allow floats like -.01, fixes #618
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Feb 1, 2017
1 parent 0a5335c commit cd92fb3
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,7 @@
#### HEAD

- Allow values like `-.01` in `isFloat()`
([#618](https://github.com/chriso/validator.js/issues/618))
- New locales
([#616](https://github.com/chriso/validator.js/pull/616))

Expand Down
2 changes: 1 addition & 1 deletion lib/isFloat.js
Expand Up @@ -11,7 +11,7 @@ var _assertString2 = _interopRequireDefault(_assertString);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var float = /^(?:[-+]?(?:[0-9]+))?(?:\.[0-9]*)?(?:[eE][\+\-]?(?:[0-9]+))?$/;
var float = /^(?:[-+])?(?:[0-9]+)?(?:\.[0-9]*)?(?:[eE][\+\-]?(?:[0-9]+))?$/;

function isFloat(str, options) {
(0, _assertString2.default)(str);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/isFloat.js
@@ -1,6 +1,6 @@
import assertString from './util/assertString';

const float = /^(?:[-+]?(?:[0-9]+))?(?:\.[0-9]*)?(?:[eE][\+\-]?(?:[0-9]+))?$/;
const float = /^(?:[-+])?(?:[0-9]+)?(?:\.[0-9]*)?(?:[eE][\+\-]?(?:[0-9]+))?$/;

export default function isFloat(str, options) {
assertString(str);
Expand Down
3 changes: 2 additions & 1 deletion test/validators.js
Expand Up @@ -1265,11 +1265,12 @@ describe('Validators', function () {
'+0.123',
'0.123',
'.0',
'-.123',
'+.123',
'01.123',
'-0.22250738585072011e-307',
],
invalid: [
'-.123',
' ',
'',
'.',
Expand Down
2 changes: 1 addition & 1 deletion validator.js
Expand Up @@ -695,7 +695,7 @@
return regex.test(str) && minCheckPassed && maxCheckPassed && ltCheckPassed && gtCheckPassed;
}

var float = /^(?:[-+]?(?:[0-9]+))?(?:\.[0-9]*)?(?:[eE][\+\-]?(?:[0-9]+))?$/;
var float = /^(?:[-+])?(?:[0-9]+)?(?:\.[0-9]*)?(?:[eE][\+\-]?(?:[0-9]+))?$/;

function isFloat(str, options) {
assertString(str);
Expand Down
2 changes: 1 addition & 1 deletion validator.min.js

Large diffs are not rendered by default.

0 comments on commit cd92fb3

Please sign in to comment.