Validates if a string is structurally a valid phone number.
This performs syntactic validation only — it does not verify that a
country calling code is real, that the digit count matches a specific
country's numbering plan, or that the number is actually assigned or
reachable (the same scope isEmail and isUrl use).
With a leading + (an explicit country code, e.g. E.164): the
remaining digits must be between 7 and 15, matching E.164's real
bounds — some countries have numbers as short as 7 digits total.
Without a leading + (a bare local number): the digits must be
between 10 and 15, since there's no declared country code to trust —
this requires something long enough to plausibly include an area or
city code rather than a bare subscriber number.
Separators (spaces, dashes, dots, parentheses) are allowed and
stripped before counting digits.
Parameters
text: string
The string to validate as a phone number
Returns boolean
boolean indicating if the string is a structurally valid phone number
Example
isPhoneNumber('+1-202-555-0173') // true isPhoneNumber('(202) 555 0173') // true isPhoneNumber('5550173') // false (too short, no area code)
Validates if a string is structurally a valid phone number.
This performs syntactic validation only — it does not verify that a country calling code is real, that the digit count matches a specific country's numbering plan, or that the number is actually assigned or reachable (the same scope
isEmailandisUrluse).+(an explicit country code, e.g. E.164): the remaining digits must be between 7 and 15, matching E.164's real bounds — some countries have numbers as short as 7 digits total.+(a bare local number): the digits must be between 10 and 15, since there's no declared country code to trust — this requires something long enough to plausibly include an area or city code rather than a bare subscriber number.