preg_match数字为负数和正数

时间:2011-02-16 01:02:50

标签: regex preg-match

我需要修复此preg_match("/^[[0-9]{0,4}$/i", $input),它还需要接受负值。谢谢

2 个答案:

答案 0 :(得分:5)

if (preg_match('/^-?[0-9]{1,4}$/', $subject)) {
    # Successful match
} else {
    # Match attempt failed
}

答案 1 :(得分:0)

与PHP中的其他内容一样,还有一个专用函数。

查看is_numeric()

相关问题