We help IT Professionals succeed at work.

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

czechmate1976
on
307 Views
Last Modified: 2012-05-11
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?
Comment
Watch Question


Try matching on the following Regular Expression:

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

Author

Commented:
Thanks a lot. Will give it a go.
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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

Author

Commented:
thanks for your help again. It gave me a good start on regex
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.