CBuzatu CBuzatu - 1 year ago 88
Javascript Question

One or two numeric digits Regex

I have the below code. It works only when I have 2 digits. If I have 1 digit doesn't work. I want to work in both cases: one or two digit.

var numberRegex = /^[1-9][0-9]$/;

I've tried something like this but unfortunately doesn't work:

var numberRegex = /^[1-9]?[1-9][0-9]$/;

Thanks for support.

Answer Source

Try this one out:


Reading what you have it looks like you don't want to accept numbers like 01.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download