Skip to content
This repository has been archived by the owner on Jun 10, 2018. It is now read-only.

Fixes issue with partial matches. #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zm1th
Copy link

@zm1th zm1th commented May 18, 2015

Hi. I don't know if this is a great way to fix this problem, but I thought I'd take a swing at it and see what you thought.

The problem: an invalid number is counted as valid because anchors (^, $) are ignored on a regular expression. I think this happens because the regex also has an OR / pipe operator ( | ).

Example:
Guatemala has eight digit phone numbers, but the number 5555 1234 123 still got through the matcher.

The regex:
/^[2-7]\d{7}|1[89]\d{9}$/

As you can see, the number does not match either of the sides of the expression delimited by the pipe. Probably, it should all be wrapped in parentheses or something. But, I don't want to change all the libphonenumber regex's to solve the problem, because then I can't update from their database very easily.

The solution is completely invalid if there are times that a partial match in the sections I have changed will happen. This was somewhat unclear to me, but I believe that at these points, we are matching the entire number.

Thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant