-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
isMobilePhone: Standardize the way number validation is done #2124
Comments
Good write-up of the current issue. I think this provides a clear picture of the situation. I would indeed keep It might be good to write a small contributing docs on |
Very good issue. A well formulated "spec" for these validators is sorely needed. The contribution guideline for phone numbers should include a robust template for test cases and some explanation of each test case, as well.
This is a good point. This kind of international prefix should be independent of the actual RegEx, since it depends on the location of the caller, not the locale of the number itself. |
Hi all,
Inspired by the discussion in one of the PR here (#2109 (comment)), I am opening up this separate issue:
Currently the isMobilePhone RegExp rules are "all over the place" in regards to how they check for numbers and do not seem to follow one standard throughout:
+
as mandatory (regardless ifstrictMode
is set or not)+
as optional00
prefix, which actually should be valid as well0
)This leads to some of these validators also matching "invalid" phone numbers without 00 or + as valid,
We should tackle this issue somehow, by:
General Format
Valid numbers can look like (illustrasted here with same fake numbers). Please ignore the white space, they are added for visual aid.
Case 1
{international call prefix}
{dialcode}
{national numbering scheme}
e.g.
00
49
172xxxxx
e.g.
011
49
172xxxxx
The issue with this is, that there are exceptions here, depending on where you are located, e.g. calling from Europe, you will use
00
, but if you are e.g. in the US, you will need to use011
(source)More initial information also on Wikipedia
Case 2
+
{dialcode}
{national numbering scheme}
e.g.
+
49
172xxxxx
This seems to be the "safest" bet, as it will correctly chose the dialcode, when you try to make a call
Case 3
and in some countries (not sure, if valid worldwide or not, this is something to be researched.)
{trunk prefix}
{national numbering scheme}
e.g.
0
172xxxxx
A quick look here shows that it usually is
0
, but not for all cases: hhttps://en.wikipedia.org/wiki/Trunk_prefixSo also something to keep in mind.
Case 4
and this is a bit of an edge case, as it is not a really valid number, but seems to be whitespread
+
{dialcode}
{trunk prefix in parentheses}
{national numbering scheme}
e.g.
+
49
(0)
172xxxxx
With that in mind, we now need to think about what
strictMode
is for, and if we need to change the way this works:Currently it is used to enforce, that the numbers start with a
+
IMHO it might make sense to change the way this works, and possibly introduce some option to control, if you want to match for certain cases or not, e.g. you might want to only allow numbers if they have the full call prefix + dial code (case 1).
Potentially it could be a good idea to introduce a way to match against a custom international prefix, which defaults to
00
though.An
options
object, with a few options that we still need to think about, e.g.matchCallPrefix
- potentially allowing to enter the "call prefix" from your regioncurrent 'strictMode'
-matchTrunkPrefix
- potentially allowing to enter the "trunk prefix" from your regioninternationalCallPrefix
- to be used, when matchCallPrefix istrue
, could e.g. default to00
TrunkPrefix
- to be used, whenmatchTrunkPrefix
istrue
, could e.g. default to0
However this is something I would need to put some more thought into.
I guess for compatibility reasons, we will have to keep the "strictMode" option work the same way as it currently does, but it potentially could be aliased, for backwards compatibility?
You could also potentially see this as a 2 step process:
a) standardize RegExp first
b) at a later point introduce the new options
What are your thoughts on this?
Kind regards,
Pano
The text was updated successfully, but these errors were encountered: