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

US Phone validation will accept phone numbers with letters #101

Open
1 task done
MaxwellGarceau opened this issue Jan 2, 2025 · 1 comment · May be fixed by #112
Open
1 task done

US Phone validation will accept phone numbers with letters #101

MaxwellGarceau opened this issue Jan 2, 2025 · 1 comment · May be fixed by #112
Assignees
Labels
type:bug Something isn't working.
Milestone

Comments

@MaxwellGarceau
Copy link
Collaborator

MaxwellGarceau commented Jan 2, 2025

Describe the bug

The regex used to validate phone numbers will accept letters. In addition, it will also accept less than the required amount of digits for each input.

Explanation

  1. The function checks for phone numbers with 12 characters (whatever they may be) to pass the length validation check. Letters are not caught here.
  2. The regex is matching anywhere between 0 and 3 characters per input field except the last field which is 0-4. This means that phone numbers with a letter in them will still pass validation because the regex will still match 3 digits.
if ( ! preg_match( '/[0-9]{0,3}-[0-9]{0,3}-[0-9]{0,4}/A', $opt_val ) ) {

Solution

Change the regex to

  • Lock in the correct amount of characters
  • Start to end matching to enforce full string matches
/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/

Steps to Reproduce

  1. Change the phone format in the test user Mailchimp account to US format
  2. Click the "Update List" button in the Mailchimp admin
  3. Submit a form with a phone number that contains a letter

Screenshots, screen recording, code snippet

mailchimp-accepts-phone-number-with-letter.mov

Environment information

No response

WordPress information

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Something isn't working.
Projects
None yet
2 participants