ASP.NET - Regular expression for UK Phone and Mobile

Asked By Jem Savery on 16-Jul-11 03:07 PM
Hi Friends, 

Can anybody give me the proper Regular expression validator for UK Phone and mobile. Here are the basic conditions.

The client deems numbers to be valid if they are classed as either:
- Mobile Numbers or
- Valid UK Format

Mobile Numbers shall be classed as:
- Commencing 07
- Being 11 digits long
- Containing only numeric characters

Valid UK format rules shall be classed as the description found on 

http://en.wikipedia.org/wiki/List_of_United_Kingdom_dialling_codes

Any help is appreciated.

Thanks in advance,
Jem.

dipa ahuja replied to Jem Savery on 16-Jul-11 03:33 PM
Try this:

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
  ControlToValidate="TextBox1"
  ValidationExpression="(\s*\(?0\d{4}\)?\s*\d{6}\s*)|(\s*\(?0\d{3}\)?\s*\d{3}\s*\d{4}\s*)"
ErrorMessage="invalid pincode"/>
 


and to search more ragular expression check this :
http://regexlib.com/
Devil Scorpio replied to Jem Savery on 16-Jul-11 03:55 PM
Hi Jem,

Assuming (07|447|\+447) are the codes for the UK, then this regex should be used

^((07|447|\+447)\d{9})$

Mobile - 07856920000
Phone - 447700912345,+447700912345
Radhika roy replied to Jem Savery on 17-Jul-11 02:04 AM
I belive that UK number often have 5 digits before your '-' character.

Follow these regular expressions.

^[0-9]{4,6}\-[0-9]{6}(?:\s(?:ext|x)\s[0-9]{3,4})?$

And here to capture the number groups:

^([0-9]{4,6})\-([0-9]{6})(?:\s(?:ext|x)\s([0-9]{3,4}))?$

And here is the expression cleaned up:

^(\d{4,6})\-(\d{6})(?:\s(?:ext|x)\s(\d{3,4}))?$
Hope this will help you.