Avatar of czechmate1976
czechmate1976
Flag for United Kingdom of Great Britain and Northern Ireland asked on

JavaScript: validating phone number so it starts with pre-defined digits

using JavaScript (jQuery)  I 'd like to validate a phone number 9 - 11 digits long, of which the starting digits should be one of the following 01 , 02, 075, 077, 078, 079 and do it live, but somehow not sure where to start. Could anyone help please?
JavaScript

Avatar of undefined
Last Comment
czechmate1976

8/22/2022 - Mon
Proculopsis


Try matching on the following Regular Expression:

  (01|02)\d{7,9}|(075|077|078|079)\d{6,8}
czechmate1976

ASKER
Thanks a lot. Will give it a go.
ASKER CERTIFIED SOLUTION
Proculopsis

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
czechmate1976

ASKER
I have come up with this one eventually and it works for me. Nevertheless, thank you very much for your help!! And apologize for not tending the question in time.
/(^(01|02)(\d{7,9}$))|(^(075|077|078|079)(\d{8}$))/

Open in new window

Your help has saved me hundreds of hours of internet surfing.
fblack61
czechmate1976

ASKER
thanks for your help again. It gave me a good start on regex