Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add scientific notation support to isNumeric validator #2464

Closed

Conversation

VivekHalder
Copy link

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)
Locale-aware formats such as 1,23e5 (where , is the decimal separator)

References:

Scientific Notation - Wikipedia

Fixes:

Fixes #2463.

Checklist:

  • PR contains only changes related to this feature; no unrelated files.
  • README updated to reflect new options.
  • References provided in the PR description where applicable.

- Updated the isNumeric function to handle scientific notation values.
- Modified the regular expression to account for both positive and negative exponents using 'e' or 'E'.
- Introduced an option to handle locales with different decimal separators.
- Preserved backward compatibility by ensuring the no_symbols option continues to function correctly.
- This change validates inputs like 1e5, 1.23E-5, and other variations of scientific notation.
- Removed unexpected spaces inside template literals in the isNumeric function.
- This fix addresses ESLint errors related to the `template-curly-spacing` rule, ensuring code style consistency.
- The changes allow the code to pass linting checks, improving overall code quality.
@VivekHalder VivekHalder closed this Oct 1, 2024
@VivekHalder VivekHalder reopened this Oct 1, 2024
@VivekHalder VivekHalder closed this Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

isNumeric does not handle Scientific Notation
1 participant