Open benada002 opened 4 months ago
@benada002
I have added a regex to handle scientific notation
^[+-]?([0-9]*[\.?])?[0-9]+(e(\+|\-)[0-9]+)?$
To handle the scientific notation you have to edit isNumeric.js file or you can copy the below code and paste it in that file where I have added the regex function in return statement
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isNumeric;
var _assertString = _interopRequireDefault(require("./util/assertString"));
var _alpha = require("./alpha");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var numericNoSymbols = /^[0-9]+$/;
function isNumeric(str, options) {
(0, _assertString.default)(str);
if (options && options.no_symbols) {
return numericNoSymbols.test(str);
}
return new RegExp("^[+-]?([0-9]*[".concat((options || {}).locale ? _alpha.decimal[options.locale]+"])?[0-9]+$" : ".])?[0-9]+(e(\\+|\\-)[0-9]+)?$")).test(str);
}
module.exports = exports.default;
module.exports.default = exports.default;
@SuvitsonHarrese you can make a pr if you like
@benada002 @SuvitsonHarrese @rubiin #2447 I had made a PR related to this issue. Could you please review it? 🙏
Describe the bug 👋 Not sure if you consider this a 🐛, but I just noticed that
isNumeric
doesn't support scientific notation. Eg. this works perfectly fine (returnstrue
):But this returns
false
, even through it's a valid numberExamples
Reproductions https://runkit.com/embed/xsw1bpnhjcgs