Regular expression for UK-Mobile numbers with optional country code and spaces in number

Recently I was given a problem that UK Mobile phone numbers
with spaces in the number are not being accepted by application
as its convenient to write numbers like (+44 0791 452 1234 OR “0791 452 1234”)
instead  (+447914521234  OR  07914521234)
(dummy number used for illustration purpose only). UK mobile numbers are of 11 digit in lenght witout spaces including zero
So length must be 11 digit excluding spaces and including zero
I found that number is being vlaidated by Regular expression
“^(\+44\s?7\d{3}|\(?07\d{3}\)?)\s?\d{3}\s?\d{3}$”

I did some googling but not found exact match so I wrote my own Expression, it was easy enoug that
I have to only replace “\d” with “(\d ?)”  that is (\dspace?). It’s all working.

Regular expression for UK-Mobile numbers with optional country code and spaces in number

OLD Pattern ^(\+44\s?7\d{3}|\(?07\d{3}\)?)\s?\d{3}\s?\d{3}$

New Pattern: ^(\+44\s?7(\d ?){3}|\(?07(\d ?){3}\)?)\s?(\d ?){3}\s?(\d ?){3}$

+44 79155 24272 – matches ^(\+44\s?7(\d ?){9}

079155 24272 – matches ^(07(\d ?){9})

Tags: , ,

One Response to “Regular expression for UK-Mobile numbers with optional country code and spaces in number”

  1. Ek says:

    Hi,

    Your expression is not working for below cases

    0116 2746190
    079155 24272
    +44 78904 23414
    1234567890
    (0800) 123 456