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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find UK Phone Number
Expression
^((\(?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}))?$
Description
UK phone number. Allows 3, 4 or 5 digit regional prefix, with 8, 7 or 6 digit phone number respectively, plus optional 3 or 4 digit extension number prefixed with a # symbol. Also allows optional brackets surrounding the regional prefix and optional spaces between appropriate groups of numbers.
Matches
01222 555 555 | (010) 55555555 #2222 | 0122 555 5555#222
Non-Matches
01222 555 5555 | (010) 55555555 #22 | 0122 5555 5555#222
Author Rating: The rating for this expression. Amos Hurd
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: No need for repetition.
Name: g1smd
Date: 8/5/2012 3:36:54 AM
Comment:
Once you have found the opening |(\(?0 once, there's no need to search for it again. The pattern ((\(?0...)|(\(?0...)|(\(?0...)) simplifies to \(?0(...|...|...) here.


Title: Modified UK pattern.
Name: g1smd
Date: 7/27/2012 4:13:22 AM
Comment:
The above pattern matches UK 2+8, 3+7 and 4+6 numbers but doesn't match UK 4+5, 5+5, 5+4 and 3+6 numbers. Also added support for 00, 011 and + international prefix with 44 country code, as well as usual leading 0 trunk prefix. "^(?:(?:(?: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})?$" 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. That requires at least 7 more, much simpler, RegEx patterns.


Title: Steve
Name: UK Telephone Number Formats in 2009.
Date: 1/18/2010 8:43:57 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. 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: no simple solution
Name: anon.
Date: 8/31/2009 9:56:32 AM
Comment:
people rarely put spaces/hyphens/parentheses/dots(!)/etc. in the 'right' places better to strip out all \D's and try to validate against a set of 'known' valid prefixes...? the headache is recognizing single phone number boundaries with this approach.


Title: What about my number
Name: Eserim
Date: 2/12/2009 10:20:57 AM
Comment:
This would fail with my phone number 5 digit prefix and 5 digit number - this must be similar or the same to several web sites that throw out my number. If you doubt such numbers exist google "seaton cab" to see taxi companies in my area.


Title: What about my number
Name: Eserim
Date: 2/12/2009 10:19:55 AM
Comment:
This would fail with my phone number 5 digit prefix and 5 digit number - this must be similar or the same to several web sites that throw out my number. If you doubt such numbers exist google "seaton cab" to see taxi companies in my area.


Title: alan
Name: alan
Date: 8/20/2006 5:38:50 AM
Comment:
It isn't correct - it doesn't check any brackets are balanced


Title: Thanks for the comment
Name: Amos Hurd
Date: 6/24/2004 8:36:45 AM
Comment:
I've updated this (and my other phone expressions which use the gate symbol "#") as I missed off a "\". The rest of the line was being taken as a "comment" because of this.


Title: 50% ok...
Name: David Keaveny
Date: 6/24/2004 8:06:01 AM
Comment:
Seems to work just fine under Javascript, but .NET bombs out with parser errors


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