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
2008-08-28 14:32:50
that example is pretty bloody awful
John Nolan
2009-08-18 13:55:13
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
2008-08-28 14:35:29
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
2008-08-28 15:00:39