Skip to content

Commit e6fbe15

Browse files
committed
fixes validatorjs#2430 - scientific notation support
1 parent 12b27a2 commit e6fbe15

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/lib/isNumeric.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import assertString from './util/assertString';
2-
import { decimal } from './alpha';
1+
import assertString from "./util/assertString";
2+
import { decimal } from "./alpha";
33

44
const numericNoSymbols = /^[0-9]+$/;
55

@@ -8,5 +8,10 @@ export default function isNumeric(str, options) {
88
if (options && options.no_symbols) {
99
return numericNoSymbols.test(str);
1010
}
11-
return (new RegExp(`^[+-]?([0-9]*[${(options || {}).locale ? decimal[options.locale] : '.'}])?[0-9]+$`)).test(str);
11+
12+
const decimalSymbol = (options || {}).locale ? decimal[options.locale] : ".";
13+
14+
return new RegExp(
15+
`^[+-]?(?:\\d+|\\d*${decimalSymbol}\\d+)(?:[eE][+-]?\\d+)?$`
16+
).test(str);
1217
}

0 commit comments

Comments
 (0)