Remove those spaces, hyphens and parentheses and use the Reg Ex patterns below to first determine the number type and then how to correctly format it. Use the detailed patterns in section 2 of this article for much better control. Extract the NSN (including spaces, hyphens and parentheses) from $2. Alternatively, the initial opening parentheses are followed by a literal without a following space or hyphen. Note: These area codes are very rare in GB, and are only available in the following places: 13873 (Langholm), 15242 (Hornby-with-Farleton), 15394 (Hawkshead), 15395 (Grange-over-Sands), 15396 (Sedbergh), 16973 (Wigton), 16974 (Raughton Head), 16977 (Brampton), 17683 (Appleby-in-Westmorland), 17684 (Pooley Bridge), 17687 (Keswick), 19467 (Gosforth). )$ The above pattern matches optional opening parentheses, followed by 00 or 011 and optional closing parentheses, followed by an optional space or hyphen, followed by optional opening parentheses. Enclose the area code part in parentheses when formatting these numbers. Note that numbers matching this pattern are not necessarily valid numbers. 020 3000 5555 or (020) 3000 5555 or in full international format, e.g. There are patterns for 2 8, 3 7 and a combined pattern for all 4 6/4 5 and 5 5/5 4 numbers.The regular expressions shown here are very similar to those found in the data files used by the open source libphonenumber project. Here the data for GB, IM, GG, GJ is combined whereas libphonenumber treats them each as separate countries.
area code/NDC if applicable, and local number); e.g. For display, there's a quite complex set of rules for GB telephone numbers because different number ranges have a different total number of digits (usually 10 or 9, occasionally 7) and there are a variety of different area code lengths in use (from 2 to 5 digits).
Alternatively, the pattern matches optional initial opening parentheses followed by the 0 trunk code (national format).