A
A
andi_fireman2016-01-22 11:22:02
Regular Expressions
andi_fireman, 2016-01-22 11:22:02

Regular expression to validate phone number in international format?

Help compose a regular expression for determining a phone number in international format.
I searched in many places, but, unfortunately, in most cases, binding to a country with its features, or several countries, but I need an international format that takes into account all the different options.
For myself, I see the following format:
"+" - obligatory character
" " "(" (space, opening bracket - possible, but not necessary, it is possible to use several characters in a row, for example, space_opening_bracket_space)
country_code - 1-3 digits, (required)
" "")" "." "(" "-" (space, close parenthesis, dot, open parenthesis, dash, or hyphen - optional, but not required,
city_or_operator_code 1-6 digits (mandatory)
" " ")" "." "-" (space, closing bracket, dot, dash or hyphen - possible, but not required, multiple characters in a row are possible)
phone number (4-12 digits separated by various garbage " " "." "-" in random order, garbage can be combined arbitrarily into a group of characters, for example " - ")
The total number of digits in the number 9-20

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
andi_fireman, 2016-01-24
@andi_fireman

Compiled, like checks everything. Who can check
/^\s*(?:\+?(\d{1,3}))?([-. (]*(\d{3})[-. )]*)?((\ d{3})[-. ]*(\d{2,4})(?:[-.x ]*(\d+))?)\s*$/gm

R
Roman Kitaev, 2016-01-22
@deliro

It's like with emails. The most correct thing is to check with a regular expression /@/
Here you just validate in three steps:
1) Check that the first character is a plus
2) Delete ONE plus and all spaces and hyphens (minuses)
3) Check if the result is an integer

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question