Regular Expressions 101

Community Patterns

Phone numbers matcher

1

Regular Expression
PCRE (PHP <7.3)

/
^ # begin \s*# some empty spaces (?: \+? # + symbol \d{1,2} # country code \s* (?(?=\)) # if followed by parens | # then dash not allowed -? # else optional dash ) )? #prefix like +380 \s* (?: (?P<leftparen>\()? # optional left paren \s* 0\d\d \s* (?(leftparen)\)|) # right paren if and only if left paren )? # operator code, starting with 0, optinally in parentheses (?(?<=\)) # if preceded by parens \s*| # then dash not allowed \s*-?\s* # else optional dash ) (?: \d | (?<= \d ) (?(sep) (?P=sep)| (?P<sep>[\-\/\ ]) ) (?= \d ) ){5,13} \s*# some empty spaces $ # end #\d\d\d (?P<separator>-?) \d\d (?P=separator) \d\d $
/
mgx

Description

no description available

Submitted by Oleksandr Sochka - 10 years ago