Skip to content

Commit cd92fb3

Browse files
committed
Allow floats like -.01, fixes #618
1 parent 0a5335c commit cd92fb3

File tree

6 files changed

+8
-5
lines changed

6 files changed

+8
-5
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#### HEAD
22

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

lib/isFloat.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var _assertString2 = _interopRequireDefault(_assertString);
1111

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

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

1616
function isFloat(str, options) {
1717
(0, _assertString2.default)(str);

src/lib/isFloat.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import assertString from './util/assertString';
22

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

55
export default function isFloat(str, options) {
66
assertString(str);

test/validators.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1265,11 +1265,12 @@ describe('Validators', function () {
12651265
'+0.123',
12661266
'0.123',
12671267
'.0',
1268+
'-.123',
1269+
'+.123',
12681270
'01.123',
12691271
'-0.22250738585072011e-307',
12701272
],
12711273
invalid: [
1272-
'-.123',
12731274
' ',
12741275
'',
12751276
'.',

validator.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@
695695
return regex.test(str) && minCheckPassed && maxCheckPassed && ltCheckPassed && gtCheckPassed;
696696
}
697697

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

700700
function isFloat(str, options) {
701701
assertString(str);

validator.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)