Need regular expression for Irish phone number

I need to check the Irish phone number, but I don’t want it to be too unfriendly, many people are used to writing down the phone number with brackets, wrapping their area code, followed by 5 to 7 digits for their number, some add spaces between area code or mobile operator.

The format of the Irish land numbers is the area code from 1 to 4 digits and from 5 to 8 digits.

eg.

(021) 9876543  
(01)9876543  
01 9876543  
(0402)39385

I am looking for a regex for Javascript / PHP.

+3
source share
4 answers

It might work. It should take into account the occurrence of spaces anywhere in the telephone number.

preg_match('|^\s*\(?\s*\d{1,4}\s*\)?\s*[\d\s]{5,10}\s*$|', $phone);

2 .

:, , :

if (preg_match('|^\s*(\(?\s*\d{1,4}\s*\)?\s*[\d\s]{5,10})\s*$|', $phone, $m))
{
    echo $m[1];
}
+1

, Validate_IE - phoneNumber, (/ , , ..).

, , , , , !

+2

If it were me, I would separate the spaces and brackets, and then check it between the minimum and maximum length.

+1
source

Source: https://habr.com/ru/post/1748146/


All Articles