Skip to content

Commit

Permalink
fix issue #2430
Browse files Browse the repository at this point in the history
  • Loading branch information
shreysinha25 committed Sep 8, 2024
1 parent ff56dcf commit 4e616a4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/isNumeric.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ 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);
return (new RegExp(`^[+-]?([0-9]*[${(options || {}).locale ? decimal[options.locale] : '.'}])?[0-9]+([eE][+-]?[0-9]+)?$`)).test(str);
}
21 changes: 21 additions & 0 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2825,6 +2825,27 @@ describe('Validators', () => {
});
});

it('should validate numeric strings with scientific notation', () => {
test({
validator: 'isNumeric',
valid: [
'2e+21',
'-3.5E-8',
'3.14e2',
'1.23e+10',
'-0.001e-5',
],
invalid: [
'e10',
'2e+',
'3.14e',
'e',
'3.14e-',
'2E+G',
],
});
});

it('should validate numeric strings without symbols', () => {
test({
validator: 'isNumeric',
Expand Down

0 comments on commit 4e616a4

Please sign in to comment.