From e6fbe1531e56f20e1c865ada9d7a24f7a2c2f5a8 Mon Sep 17 00:00:00 2001 From: OlaOluwalekan Date: Sun, 27 Oct 2024 10:25:11 +0000 Subject: [PATCH] fixes #2430 - scientific notation support --- src/lib/isNumeric.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/lib/isNumeric.js b/src/lib/isNumeric.js index 4cc7ea5b3..313c96ecd 100644 --- a/src/lib/isNumeric.js +++ b/src/lib/isNumeric.js @@ -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]+$/; @@ -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); }