- The first Regular Expression Library on the Web!

Please support RegExLib Sponsors


Regular Expression Details

Title Test Find Modified UK Phone Number
Modified version of UK phone number regular expression. Now allows +44 national code in addition to extension numbers of 3 or 4 digits. Previous expression was: ^((\(?0\d{4}\)?\s?\d{3}\s?\d{3})|(\(?0\d{3}\)?\s?\d{3}\s?\d{4})|(\(?0\d{2}\)?\s?\d{4}\s?\d{4}))(\s?#(\d{4}|\d{3}))?$
+447222555555 | +44 7222 555 555 | (0722) 5555555 #2222
(+447222)555555 | +44(7222)555555 | (0722) 5555555 #22
Author Rating: The rating for this expression. Amos Hurd
Your Rating
Bad Good

Enter New 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: Comprehensive GB telephone number pattern matching.
Name: g1smd
Date: 10/27/2012 12:12:23 PM
@ray : Your RegEx pattern ^(((\+44\s?...|\(?0...\)?)\s?.......)|((\+44\s?...|\(?0...\)?)\s?.......)|((\+44\s?...|\(?0\...\)?)\s?.......))(\s?\#(\d{4}|\d{3}))?$ is very inefficient. Having found the leading +44 or leading 0 once, why would you keep on searching for it again and again for each different area code length? The code should simplify to ^((\+44\s?|\(?0) ONCE followed by the different area code and number combinations. Your code also does not match UK 5+5 or 5+4 format numbers. Try this: ^\(?(?:(?:0(?:0|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}|8(?:00[\s-]?11[\s-]?11|45[\s-]?46[\s-]?4\d))(?:(?:[\s-]?(?:x|ext\.?\s?|\#)\d+)?)$ which matches far more format variations and some common dial prefixes. See also:

Title: UK 2+8 format
Name: g1smd
Date: 8/5/2012 12:40:06 PM
@colin ** +442392123456 matches but +44-2392-123456 does not. ** That's partly because Portsmouth numbers use the 2+8 format, e.g. +44-23-9234-5678. However the pattern should also be modified to accept spaces or hyphens.

Title: UK RegEx patterns.
Name: g1smd
Date: 7/27/2012 4:33:52 AM
Numbers should never be DISPLAYED in +44 (0)20 3000 5555 format. The (0) is not valid in the international format. The following 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. The pattern was used in Java hence the double escaping. "^(?:(?:(?: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 allows the user to enter the number in any way they feel happy with. Once the phone number has been detected, it is important to then tidy it up and show 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 correcting the format to space the area code and local number correctly. That process requires at least 7 more, much simpler, RegEx patterns matching various leading digits and number lengths, detailed elsewhere.

Title: Ignore non whitespace
Name: Colin
Date: 3/29/2011 3:22:57 PM
Hi, +442392123456 matches but +44-2392-123456 does not. Also we commonly see people putting both interanation and nation numbers down, for example +44(0)2392-123456, any way that can be handled? Cheers

Title: UK Telephone Number Formats
Name: Steve
Date: 12/25/2009 2:33:11 AM
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. 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. 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!

Title: Some UK numbers are only 10 digits
Name: Ray
Date: 1/16/2009 6:48:26 AM
Fails on my home number which is of the form 01606 12 345. I modified it to: ^(((\+44\s?\d{4}|\(?0\d{4}\)?)\s?\d{2,3}\s?\d{3})|((\+44\s?\d{3}|\(?0\d{3}\)?)\s?\d{2,3}\s?\d{4})|((\+44\s?\d{2}|\(?0\d{2}\)?)\s?\d{4}\s?\d{4}))(\s?\#(\d{4}|\d{3}))?$ which works for me but i haven't tested thoroughly. Amusingly BT can't validate my number either!

Title: PHP w/ CakePHP
Name: Dave
Date: 8/11/2008 7:55:12 AM
I tried implementing this into the CakePHP 1.2 phone validation method as the default is for US numbers only, doesn't seem to validate which is kind of strange.

Title: Comments
Name: Mukesh Pandey
Date: 9/2/2004 2:56:01 AM
Very Nice for UK Numbers

Title: If you comment ...
Name: Amos Hurd
Date: 7/8/2004 11:07:51 AM
If there are problems, please let me know under what circumstances the expression fails. Simple testing via the "Test" link seemed to work fine for .Net today.

Title: not for .Net
Name: Gus
Date: 7/8/2004 11:01:52 AM
This expr. does not work in .net for some reason

Title: Updated
Name: Amos Hurd
Date: 6/24/2004 8:42:26 AM
Updated to preceed the "#" symbol with "\" to avoid the rest of the line being taken as a comment.

Copyright © 2001-2018, | ASP.NET Tutorials