How do you validate the numeric values with Hypen's (-) ? I just want to validate the numeric value with Hypen's and without Hypen's. Thank you so much !
For example 555 or 5-55
CodePudding user response:
You may use preg_match
with the regex pattern ^[0-9-] $
:
$input = "867-5309";
if (preg_match("/^[0-9-] $/", $input)) {
echo "MATCH"; // prints MATCH
}