I want to use preg_match to match numbers 1 - 21. How can I do this using preg_match? If the number is greater than 21 I don't want to match anything.
example preg_match('([0-9][0-1]{0,2})', 'Johnathan 21');
Copied from comment above:
I suggest matching simply ([0-9]{1,2}) (maybe wrapped in \b, based on input format) and filtering the numeric value later, in PHP code.
See also Raymond Chen's thoughts on the subject.
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