I need a RegEx to do the validation (using Laravel, a php framework) for a swiss phone number which has to fit this format:
+41 11 111 11 11
The "+41" part has to be exactly this way while the rest (11 111 11 11) can be any number between 1 and 9.
The function that invokes the RegEx looks like this:
$regex = "thisIsWhereINeedYourHelp";
if (preg_match($regex, $value)) {
return true;
}
return true;
Thanks for your help!
This is the pattern I use:
/(\b(0041|0)|\B\+41)(\s?\(0\))?(\s)?[1-9]{2}(\s)?[0-9]{3}(\s)?[0-9]{2}(\s)?[0-9]{2}\b/
it matches all the following:
+41 11 111 11 11
+41 (0) 11 111 11 11
+41111111111
+41(0)111111111
00411111111
0041 11 111 11 11
0041 (0) 11 111 11 11
011 111 11 11
0111111111
any of the spaces can be left out and it checks for the word and non word boundaries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With