In the current project I'm looking at I have two input fields for telephone numbers.
1. UK Mobile Phone Number
2. UK Landline Number
They each have their own regex checks .
It's been requested that we should have just the one input field; this could be a UK landline OR UK Mobile . So I'd like to merge the 2 regexes together. Which is real easy but I found googling the exact answer very difficult. So I thought I'd note it here.
So here's the two seperate Regex's
Regex for UK Mobile Numbers.
^(\+44\s?7(\d ?){3}|\(?07(\d ?){3}\)?)\s?(\d ?){3}\s?(\d ?){3}
Regex for UK Landlne Phone Numbers
^\(?0( *\d\)?){9,10}$
So to use both we can add the OR statement which is '|' And to group the two sides together using the '(' and ')' which gives us the following combined statement.
(
^(\+44\s?7(\d ?){3}|\(?07(\d ?){3}\)?)\s?(\d ?){3}\s?(\d ?){3})|(^\(?0( *\d\)?){9,10}$)
No comments:
Post a Comment