preg_match to find two digit numbers with above 14
I am using the below code to identify the text or nothing followed by 2 or 3 digit numbers
preg_match("/^[0-9]{2,3}$/",trim($textMessage),$result)
It works fine. But I need to find the digit from above 14 only. Bu开发者_如何学Ct the above code matches from 10 itself.
Please help. Thanks in advance.
Regex shouldn't really be used for comparisons like this - it's more for pattern matching. So, keep your regex the way it is and test $result
:
<?php
$textMessage = '123';
preg_match("/^[0-9]{2,3}$/",trim($textMessage),$result);
print_r($result);
if($result[0] > 14)
{
// do something here
}
?>
Easy. you switch your number part from
[0-9]{2,3}
to this:
(1[5-9])|([2-9][0-9])|([1-9][0-9]{2})
精彩评论