We help IT Professionals succeed at work.

How can I allow 0, 10 or 13 digits only with regular expression/javascript

293 Views
Last Modified: 2017-04-21
I am using the following to accept only 0 or 10 digits, but I need to change it to allow 0, 10 or 13. Can someone assist?

 if(/^(\d{0}|\d{10})$/.test(carCount) == false) {
......

Open in new window

Comment
Watch Question

Remote Training and Programming
CERTIFIED EXPERT
Top Expert 2015
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Mukesh YadavFull Stack Developer
CERTIFIED EXPERT

Commented:
Add one more or check for 13 digits:

 if(/^(\d{0}|\d{10}|\d{13})$/.test(carCount) == false) {
....
}

Open in new window


That's it!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*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.