feat: Add scientific notation support to isNumeric validator #2467
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request: Enhancing Numeric Validation with Scientific Notation and Locale Support
This pull request introduces significant enhancements to the
isNumeric
function, improving its ability to validate more complex numeric formats, including scientific notation and locale-aware decimal separators.Key Enhancements:
1. Scientific Notation Support
The
isNumeric
function now fully supports scientific notation, making it easier to validate numbers in exponential form. Inputs such as1e5
,1.23E-5
, and similar formats with both positive and negative exponents are correctly identified as valid numeric strings. This improvement ensures the validation of scientific data and other formats that utilize exponents.Examples:
1e5
(Scientific notation with a positive exponent)1.23E-5
(Scientific notation with a decimal and negative exponent)2. Locale-Aware Decimal Separators
We have introduced a locale-aware option, allowing
isNumeric
to handle different decimal separators based on region-specific formats. This makes numeric validation more flexible and adaptable to various international standards.Examples:
1,23e5
(Where,
is used as the decimal separator in certain locales)This enhancement adds a more global-friendly approach, accommodating numeric formats that vary by region.
3. Backward Compatibility
The
no_symbols
option remains intact to ensure that existing behavior is preserved. This option can still be used to restrict symbols like+
and-
, ensuring no regressions for users who rely on this setting.Fixes:
Fixes #2463 .
Checklist:
Usage
To validate numbers in scientific notation or locale-specific formats, pass the appropriate options to the
isNumeric
function. The function now seamlessly handles both traditional and scientific numeric formats, offering a wider range of use cases.Example Usage: