0

I'm trying to create a Regex that validates a phone number to make sure it starts from 0700 - 0792. I initially had a Rex to validate from 0700 - 0789 which was:

/^07[0-8][0-9]/

And now I dont know how to modify it to have it in such a way that if the 3rd digit is 9 then it should only allow the 4th digit to be only 0,1 or 2.

Thank you

2 Answers 2

1

Change your regex to,

/^07(?:[0-8][0-9]|9[012])/
Sign up to request clarification or add additional context in comments.

Comments

1
^07(?:[0-8][0-9]|9[0-2])$

You can or the extra 3 numbers.See demo.

https://regex101.com/r/vV1wW6/14

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.