您如何使用 Hypen 的 (-) 驗證數值?我只想用 Hypen 和沒有 Hypen 來驗證數值。非常感謝 !
例如 555 或 5-55
uj5u.com熱心網友回復:
您可以使用preg_match正則運算式模式^[0-9-] $:
$input = "867-5309";
if (preg_match("/^[0-9-] $/", $input)) {
echo "MATCH"; // prints MATCH
}
uj5u.com熱心網友回復:
為此,我建議從網站:
https://www.phpliveregex.com/
采用
例如,我在鏈接中寫了一個 preg_match :?
https://www.phpliveregex.com/p/Ep6
你可以看到
我建議的代碼:
$input = "867-5309";
echo preg_match("/^[0-9-] $/", $input) ? 'MATCH' : 'Not MATCH';
我希望它會有用
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/462059.html
