Question

I'm trying to validate Swedish phonenumber using PHP's preg_match_all().

RegEx:

$pattern = '~(?>(\()?0\d(?(1)\))\s?+)?+\d\d\s?+(?>\d{3}\s?\d{3}|(?:\d\d\s??){3})~';

$haystack = 'bla bla bal 0701234567 bla 010-338000  bafdsa'; ...and so on..

Pattern should find:

  • 7-11 numeric chr (excluding separators, dash(-) and whitespaces( ).
  • Always start with an zero(0)
  • Between every number there is supposed to be an optional dash or whitespace.

Examples:

01-23456
012-34 56
012 34 56
01234567
0123-456789

Any suggestions?

Was it helpful?

Solution

Perhaps something like:

0([-\s]?\d){6,10}

So, a 0, followed by 6 to 10 groups of an optional space or dash followed by a digit.

OTHER TIPS

/^07(0|2|3|6|9)\d{7}$/g

this will work for the local number starts with the following initials: 070, 072, 073, 076, 079 Mobile phone networks example: 076xxxxxxx x will be the numeric

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top