I have been trying to figure out how to return true if any number but not if only 0 or contains any decimal .
that is
1 //true
23 //true
10 //true
0.2 //false
10.2 //false
02 //false
0 //false
I have made this regex so far and it's working fine but it also allows 0 which I don't want
/^[0-9]+$/.test(value);
I tried to search my best and tried these regex so far but failed
/^[0]*[0-9]+$/
/^[0-9]+[^0]*$/
I am not good in regex at all. Thank you anticipation.
You were close: /^[1-9][0-9]*$/
.
The leading [1-9]
forces the number to have a most-significant digit which is not 0
, so 0
will not be accepted. After that, any digit can come.
Finally, a number containing .
is not accepted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With