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

Phone Number matches incorrectly #240

Open
SkeletalDemise opened this issue Dec 2, 2021 · 4 comments
Open

Phone Number matches incorrectly #240

SkeletalDemise opened this issue Dec 2, 2021 · 4 comments

Comments

@SkeletalDemise
Copy link
Contributor

I've had numerous false positives with the phone number regex that are obviously wrong. All of these match:

0000000000000
0123456789
3333333333333
3333333333
4444444444444
22223333333
-1606586780

The last one is potentially valid but -1 is not valid in a phone number. +1 is. If it can't be less broad then make the rarity 0.

@RackReaver
Copy link
Contributor

Might need to split this into multiple regex as there are a lot of different standards

  • 11 digit (x-xxx-xxx-xxxx)
  • 10 digit (xxx-xxx-xxxx)
  • 7 digit (xxx-xxxx)

@ghost
Copy link

ghost commented Dec 3, 2021

Might need to split this into multiple regex as there are a lot of different standards

  • 11 digit (x-xxx-xxx-xxxx)

  • 10 digit (xxx-xxx-xxxx)

  • 7 digit (xxx-xxxx)

We have an issue for this. #227

@behrad-ahmadpour
Copy link

@RackReaver
We can add a Country code field that tests the input number without country code. also, a number can be identified by + at the first of it

@Ajay1812
Copy link

@SkeletalDemise Can we use the Python module phonenumbers by running the following command: pip install phonenumbers? Here's some sample code you can review.

import phonenumbers
def is_valid_phone_number(phone_number):
    try:
        # Parse the phone number
        parsed_number = phonenumbers.parse(phone_number, None)
        
        # Check if the number is valid
        is_valid = phonenumbers.is_valid_number(parsed_number)
        
        return is_valid
    except phonenumbers.phonenumberutil.NumberFormatException:
        # Handle invalid phone number format
        return False

# Example usage
phone_number = "+1 650-555-1234"  # Replace with the phone number you want to validate
if is_valid_phone_number(phone_number):
    print(f"The phone number {phone_number} is valid.")
else:
    print(f"The phone number {phone_number} is not valid.")

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

No branches or pull requests

4 participants