How does PHP use regular matching to prevent users from entering negative numbers?

$matches = -50;
$res = preg_match("/[1-9]{1,10}/",$matches);
print_r($res);  //1

as shown in the code above, I don"t match the-sign regularly, but I can still enter a negative number. What"s going on?
how can I use regular expressions to disable the input of negative numbers.

Feb.24,2022

if you don't have to be regular, you don't have to be irregular.
if you have to use it, then

</span>

^$

$matches = -50;
$res = preg_match('/^[1-9]{1,10}$/',$matches);
print_r($res);  //0

if you just want to use regularity to determine whether it is a negative number, you can do so

$matches = -50;
$res = preg_match('/-/',$matches);
print_r($res);//1, 

if the requirement is to determine whether it is a non-negative number, it can also be like this

$matches = -50;
if(is_numeric($matches) && $matches >= 0) {
    print_r('');
} else {
    print_r('');
}
Menu