- The first Regular Expression Library on the Web!

Please support RegExLib Sponsors


Regular Expression Details

Title Test Find Pattern Title
Validates UK domestic landline phone numbers. Valid formats are: 029 99999999 or 029 9999 9999; 0199 9999999 or 0199 999 9999; 01999 99999; 01999 999999; 019999 9999; 019999 99999. These formats are taken from the official guidelines from Ofcom, the organisation responsible for UK telecoms issues. Brackets are not valid and STD code must be entered.
020 1234 5678 | 0123 4567890 | 01234 456789
02476 123456 | 0845 123456 | 07712 345678
Author Rating: The rating for this expression. John Chivers
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: Pattern matching.
Name: g1smd
Date: 7/27/2012 5:36:49 AM
Add the ^ and $ anchoring to prevent numbers that are too long from being entered. Once you have found the initial '0' there is no need to search for it again. Once you have found the first '1' there is no need to search for it again. This will parse a bit faster: "^0(?:(?:2\d\s?\d{4}\s?\d{4})|1(?:(?:\d{2}\s?\d{3}\s?\d{4})|(?:\d{3}\s?(?:\d{5}|\d{3}\s?\d{3}))|(?:\d{4}\s?\d{4,5})))$" It copes with UK numbers in 2+8, 3+7, 4+6, 4+5, 5+5 and 5+4 format. Adding additional support for +44 and 00 44 as well as optional parentheses is easy: "^(?:(?:(?:0(?:0\s?|11\s)|\+)44\s?(?:\(?0\)?\s?)?)|(?:\(?0))(?:(?:2\d\)?\s?\d{4}\s?\d{4})|1(?:(?:\d{2}\)?\s?\d{3}\s?\d{4})|(?:\d{3}\)?\s?(?:\d{5}|\d{3}\s?\d{3}))|(?:\d{4}\)?\s?\d{4,5})))$" 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 several more, much simpler, RegEx patterns this time matching various leading digits and number lengths, as detailed elsewhere.

Title: UK numbers can be too long
Name: Rich Franzmeier
Date: 9/30/2006 12:26:38 PM
The regex doesn't prevent the user from entering numbers that are too long: ex: 029 9823749823742983749238749284379

Copyright © 2001-2018, | ASP.NET Tutorials