Skip to content

Commit

Permalink
fixes validatorjs#2430 - scientific notation support
Browse files Browse the repository at this point in the history
  • Loading branch information
OlaOluwalekan committed Oct 27, 2024
1 parent 12b27a2 commit e6fbe15
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/lib/isNumeric.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assertString from './util/assertString';
import { decimal } from './alpha';
import assertString from "./util/assertString";
import { decimal } from "./alpha";

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

Expand All @@ -8,5 +8,10 @@ export default function isNumeric(str, options) {
if (options && options.no_symbols) {
return numericNoSymbols.test(str);
}
return (new RegExp(`^[+-]?([0-9]*[${(options || {}).locale ? decimal[options.locale] : '.'}])?[0-9]+$`)).test(str);

const decimalSymbol = (options || {}).locale ? decimal[options.locale] : ".";

return new RegExp(
`^[+-]?(?:\\d+|\\d*${decimalSymbol}\\d+)(?:[eE][+-]?\\d+)?$`
).test(str);
}

0 comments on commit e6fbe15

Please sign in to comment.