views:

1410

answers:

3

How do I validate a UK phone number in C# using a regex?

+2  A: 

There is a good searchable catalog of regular expressions at the Regular Expression Library. There is at least one regular expression for UK phone numbers in this catalog.

bmatthews68
that example is pretty bloody awful
John Nolan
A: 

Well the format of a UK phone number is 0[areacode x4][numberx6] however I think that changes per region - it's definitely applicable for my region which has a 4 digit area code by Bristol for example has a 3 digit code.

I'm not too good at regex but this works for me (in preg mode):

0[1-9]{3,4}[0-9]{6}
Ross
A: 

@Ross

That doesn't take into account spaces (e.g. 01234 567890) or internationalisation (eg +44 1234 567890)

Although, if the OP doesn't want to take those factors into account, that's not an issue.

ZombieSheep