Skip to content

fix: Allow empty strings for email and number validation in validators.ts #2811

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

Merged
merged 6 commits into from
Mar 27, 2024

Conversation

abdulbasithqb
Copy link
Contributor

Description

Updated the email and number validators in validator.ts to allow empty strings. Now, empty email and number strings are considered valid.

Motivation

issue #2807

Changelog

  • Modified the email validator logic to allow empty strings explicitly.
  • Modified the number validator logic to consider empty strings as valid.

Additional info

This change ensures a more permissive validation for both email and number fields. If a field is not required, no error message will be displayed when users clear their input.
If you encounter any issues or have further suggestions, please let me know.

Results

1. Invalid Email 2. Invalid Number
1. Email Cleared 2. Number Cleared

Copy link

stale bot commented Mar 13, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Mar 13, 2024
@stale stale bot removed the wontfix label Mar 20, 2024
@brianangulo
Copy link

Thank you! @Inbal-Tish @adids1221 could you please take a peek whenever able 🙏 ? This one has been open for a few months now

@@ -8,9 +8,15 @@ const priceRegEx = /^[0-9]{1,9}([.][0-9]{1,2})?$/;

const validators = {
required: (value = '') => !_.isEmpty(value),
email: (value = '') => new EmailValidator().isValid(value),
email: (value = '') => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could be a breaking change for other users.
I think we should add a new validation optionalEmail that will validate this case (empty string) and leave the email validator as it is.

Copy link
Contributor

@adids1221 adids1221 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left another small comment since it could be a breaking change to other users that are using this validation even though the email field isn't required.

@abdulbasithqb
Copy link
Contributor Author

abdulbasithqb commented Mar 21, 2024

Left another small comment since it could be a breaking change to other users that are using this validation even though the email field isn't required.

changes are made as per the suggestion

@adids1221 adids1221 self-requested a review March 27, 2024 10:18
@adids1221 adids1221 self-assigned this Mar 27, 2024
@adids1221 adids1221 merged commit a575b87 into wix:master Mar 27, 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.

4 participants