feat: Add scientific notation support to isNumeric validator #2466
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.
Description
This PR enhances the isNumeric function to support scientific notation values, addressing the issue where such values were not validated correctly. The following improvements were made:
1. Scientific Notation Support: The regular expression has been updated to account for both positive and negative exponents using the 'e' or 'E' syntax. This allows inputs like 1e5, 1.23E-5, and similar formats to be validated.
2. Locale-Aware Decimal Separators: Introduced an option to handle different decimal separators based on locale, enhancing the flexibility of numeric validation across regions.
3. Backward Compatibility: The no_symbols option has been preserved to ensure that users who disable symbols (like + or -) will not experience regressions with this update.
Example of Supported Inputs:
1e5
(scientific notation with a positive exponent)1.23E-5
(scientific notation with a decimal and negative exponent)1,23e5
(where , is the decimal separator)References:
Scientific Notation - Wikipedia
Fixes:
Fixes #2463.
Checklist: