CBuzatu CBuzatu - 2 months ago 5x
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.


Try this one out:


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