RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find UK Telephone Numbers
Expression
((\+44\s?\(0\)\s?\d{2,4})|(\+44\s?(01|02|03|07|08)\d{2,3})|(\+44\s?(1|2|3|7|8)\d{2,3})|(\(\+44\)\s?\d{3,4})|(\(\d{5}\))|((01|02|03|07|08)\d{2,3})|(\d{5}))(\s|-|.)(((\d{3,4})(\s|-)(\d{3,4}))|((\d{6,7})))
Description
Matches over 18 different combinations for UK phone numbers that I could find. If there are any errors please get in touch.
Matches
0121 111 1111|+44 (0)21 444 4444|07941 111 111|07941 111111|(+44) 121 222 3333
Non-Matches
0121_111_3333
Author Rating: The rating for this expression. Darren Moore
Source
Your Rating
Bad Good

Enter New Comment

Title
 
Name
 
Comment
 
Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: UK telephone number matching.
Name: g1smd
Date: 7/27/2012 5:58:38 AM
Comment:
There's no need to keep repeating the +44 or the leading 0 within the pattern. Find it once, then parse the number from left to right. The following pattern allows the user to enter any UK number in any format they are happy with: "^(?:(?:(?:0(?:0\\s?|11\\s)|\\+)44\\s?(?:\\(?0\\)?\\s?)?)|(?:\\(?0))(?:(?:\\d{5}\\)?\\s?\\d{4,5})|(?:\\d{4}\\)?\\s?(?:\\d{5}|\\d{3}\\s?\\d{3}))|(?:\\d{3}\\)?\\s?\\d{3}\\s?\\d{3,4})|(?:\\d{2}\\)?\\s?\\d{4}\\s?\\d{4}))(?:\\s?\\#\\d{3,4})?$" It matches 020 3000 5555 (national), (020) 3000 5555 (national with parentheses around area code), +44 20 3000 5555 (international), 00 44 20 3000 5555 (as dialled from Europe), 011 44 20 3000 5555 (as dialled from US), as well as a few common but nevertheless non-valid formats such as +44 (0)20 3000 5555, 0203 000 5555, +44(0) 2030 005 555 and so on. The pattern copes with numbers beginning 011, 00 or + with 44 country code or with 0 trunk prefix, either of which is followed by area code and phone number. It copes with UK numbers in 2+8, 3+7, 4+6, 4+5, 5+5, 5+4 and 3+6 format. Once the phone number has been detected, it is important to then tidy it up and display it with the spacing corrected per number type (e.g. +44 20 3000 5555 in place of 00 44(0) 203 000 5555 etc), especially removing the (0) if present on an international format number and altering the display format to space the area code and local number correctly. That process requires several more, much simpler, RegEx patterns this time matching various leading digits and number lengths, as detailed elsewhere.


Title: The UK system is a LOT more complex than that.
Name: Steve.
Date: 11/4/2011 4:34:24 PM
Comment:
Most UK telephone numbers can have either 9 or 10 digits after the 0 trunk prefix. The initial 0 is omitted when calling from abroad. 01 and 02 area codes should have parentheses around them if the local number part does not begin with a 0 or 1. 01 and 02 area codes do not have parentheses around them if the local number part begins with a 0 or 1. These are National Dialling Only ranges. All other area codes do not have parentheses around them as the area code is required for all calls. Number formats are expressed as: 2+8 to represent (02x) xxxx xxxx [in 5 areas] or 05x xxxx xxxx or 070 xxxx xxxx or 076 xxxx xxxx. 3+7 to represent (011x) xxx xxxx [in 6 areas] or (01x1) xxx xxxx [in 6 areas] or 03xx xxx xxxx or 08xx xxx xxxx or 0800 xxx xxxx or 09xx xxx xxxx. 3+6 to represent 0500 xxxxxx or 0800 xxxxxx. 4+6 to represent (01xxx) xxxxxx [in 580 areas] or 07xxx xxxxxx. 4+5 to represent (01xxx) xxxxx [in 41 areas]. 5+5 to represent (01xx xx) xxxxx [in 12 areas]. 5+4 to represent (01xx xx) xxxx [in 1 area]. Valid formats include: (011x) - 3+7. (01x1) - 3+7. (01xxx) - 4+6 or 4+5. (01xx xx) - 5+5 or 5+4. (02x) - 2+8. 03xx - 3+7. 05x - 2+8. 0500 - 3+6. 07xxx - 4+6. 070 - 2+8. 076 - 2+8. 08xx - 3+7. 0800 - 3+7 or 3+6. 09xx - 3+7. There are a small number of exceptions such as 0800 1111 and 0845 4647. The UK system is quite complex!


Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials