I have this regex:
/^[0-9]+$/i
Used in this code:
preg_match('/^[0-9]+$/i', $var);
I want the following to be true: $var = 1; $var = 50; $var = 333;
And the following to be false: $var = 0; $var = 01; $var = 'abc';
I think what I have works so far except for the "0" part..?
I went through this guide (http://www.phpf1.com/tutorial/php-regular-expression.html) but was unable to come up with a complete answer.
Any help would be appreciated, thanks!
/^[1-9][0-9]*$/
Means: A non-zero digit followed by an arbitrary number of digits (including zero).
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