Reputation: 169
I use this to test for digits
/^\d+$/
But I need to make sure that it's greater than zero, while still allowing 0000123123123 for instance.
Upvotes: 5
Views: 18722
Reputation: 122
It is correct regex for positive digits.
/^[1-9]\d*$/g
The previous answer not correct for 0123.
Upvotes: 6
Reputation: 183251
You can write:
/^\d*[1-9]\d*$/
(zero or more digits, followed by a nonzero digit, followed by zero or more digits).
Upvotes: 20