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 #2465

Closed
wants to merge 2 commits into from

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 that the `no_symbols` option continues to function correctly.
- This change ensures that inputs like `1e5`, `1.23E-5`, and other variations of scientific notation are now validated properly.
@VivekHalder VivekHalder changed the title fix: resolve template literal spacing issues in isNumeric function feat: Add scientific notation support to isNumeric validator Oct 1, 2024
@rubiin
Copy link
Member

rubiin commented Oct 1, 2024

the pr shows zero files changed. Could you push the changes?

@VivekHalder
Copy link
Author

the pr shows zero files changed. Could you push the changes?

Sir, I have made a mistake in this pr, i have again made a new pr, #2467. Could you please check that out?

@rubiin
Copy link
Member

rubiin commented Oct 1, 2024

closing this then

@rubiin rubiin 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
2 participants