Reputation: 357
Im trying to validate a Uk telephone number,
Im using this regexp:
^(((\+44\s?\d{4}|\(?0\d{4}\)?)\s?\d{3}\s?\d{3})|((\+44\s?\d{3}|\(?0\d{3}\)?)\s?\d{3}\s?\d{4})|((\+44\s?\d{2}|\(?0\d{2}\)?)\s?\d{4}\s?\d{4}))(\s?\#(\d{4}|\d{3}))?$
This match well with almost number possibilities but these does not match:
+44 (0)7518 123 456 or +44(0)7518123456
Any one know how to amend it to achieve it?
Regards!
Upvotes: 1
Views: 1899
Reputation: 424993
This matches all your edge cases:
^(\+?44)?(?=(.*?\d){10,})( ?\(\d+\))?[ \d]+(#\d+)?$
The look ahead asserts there are at least 10 digits not including the country prefix.
See demo with all edge cases you have mentioned.
Upvotes: 0
Reputation: 3575
You can simplify this quite a lot. Check out this regex101 to see if it matches your needs: http://regex101.com/r/xP6lE7/1
^(\+?44)?(\(\d+\))?[\d ]+(#\d+)?$
Upvotes: 1