I need a regex to allow either a single 0 or any other number of digits that do not start with zero so:
0 or 23443 or 984756 are allowed but 0123 is not allowed.
I have got the following which allows only 1 to 9
[1-9]\d
Look for a lone 0 or 1-9 followed by any other digits.
^(0|[1-9]\d*)$
If you want to match numbers inside of larger strings, use the word boundary marker \b in place of ^ and $:
\b(0|[1-9]\d*)\b
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