Regular Expressions 101

Community Library

Community Library Entry

-1

Regular ExpressionOpen Workspace

r"
^\(?(?P<prefix>(?=1)|\+|(?:0(?:0(?:0|1|9)?|1(?:0|1))?|119))[-. ]?\(?(?P<CC>1([-. ]?)[0-9]{3}|2(?:0|[0-9]{2})|3(?:[0-469]|[0-9]{2})|4(?:[013-9]|[0-9]{2})|5(?:[1-8]|[0-9]{2})|6(?:[0-6]|[0-9]{2})|7(?:[-. ]?[67]|[0-9]{3})|8(?:[1246]|[0-9]{2})|9(?:[0-58]|[0-9]{2}))(?:\)?[-. ])?(?P<number>(?:[0-9]+[-. ]?)+)$
"
mg

Description
Created·2015-09-28 09:35
Type·Match
Flavor·Python

Validates all possible international phone number formats. Icludes almoust all of the international call prefixes, all of the differing lenghts of country codes. The parts of number will always be recognised correctly.

Additionally you could add limitations of the phone number's lenght

Submitted by Ādams Muzikants
Open Workspace