doubt when passing a preg_match parameter

0

I have a doubt I want to pass a parameter within the rule eg the value that is entered is 1500-2000 and I want it to only validate the numerical value with the hyphen in between. I still need something to detect the script.

CODE:

if(preg_match('/^[0-9]+$/',"1500-2000")){
echo "filtro precio";
}
    
asked by Matias 06.10.2018 в 18:53
source

1 answer

2

You must modify your regular expression for the new pattern.

You could use /^[0-9]+\-[0-9]+$/ to include the middle dash and the new group of numbers.

if(preg_match('/^[0-9]+\-[0-9]+$/',"1500-2000")){
    echo "filtro precio";
}
    
answered by 06.10.2018 / 18:59
source