Modify existing RegEx for mobile phone number validation

Andy Green
Andy Green used Ask the Experts™
on
Hi

I have inhertited a Reg Ex patter to validate mobile phone numbers.

/^(\+44\s?7\d{3}|\(?07\d{3}\)?)\s?\d{3}\s?\d{3}$/g;

I need to change it to validate an 8 digit number, starting with 2.

Can anyone help please.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Terry WoodsIT Guru
Most Valuable Expert 2011

Commented:
Do you mean in addition to other numbers that it accepts?
IT Guru
Most Valuable Expert 2011
Commented:
If it's an additional case that also needs to be accepted then this pattern is a clear way of covering it with minimum complexity:
^((\+44\s?7\d{3}|\(?07\d{3}\)?)\s?\d{3}\s?\d{3}|2\d{7})$

Open in new window

The whole pattern, except the ^ and $, has been wrapped in round brackets, and this part:
|2\d{7}

Open in new window

has been added as an alternative the the previous pattern.
Terry WoodsIT Guru
Most Valuable Expert 2011

Commented:
The pipe character is like a logical OR, and the 2\d{7} says to match a number 2 then 7 more digits. If you need to allow for spaces, let me know some examples and I can edit the pattern to suit.
Terry WoodsIT Guru
Most Valuable Expert 2011

Commented:

Author

Commented:
Hi

Thanks for solutions and additional info.

A

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial