user3318208
user3318208

Reputation: 93

Regex not start in zero if single digit

I have a 5 textboxes that can input only numbers. I used /^[1-9][0-9]+$/, but what I need is if single digit is zero allow it.

enter image description here

Just like the picture above, I have 5 textboxes if 1 of the textbox is already equal the quantity the other textbox should allow a zero value. It can't be greater or lower than in quantity.

Upvotes: 0

Views: 1271

Answers (2)

Arun P Johny
Arun P Johny

Reputation: 388316

Try a or condition

/^([1-9][0-9]*|0)$/

Upvotes: 2

SomeKittens
SomeKittens

Reputation: 39522

Your best bet is:

/^\d+$/

Which will allow only a number of one or more digits.

Breakdown

/ start of regex
^ matches beginning of string
\d matches any digit
+ modifies the above to match one or more
$ matches the end of line
/ ends the regex

Upvotes: 4

Related Questions