Ric*_*ich 1 php regex floating-point numbers pattern-matching
我想要一个模式来创建一个"is_id()"函数来验证mysql查询之前的用户输入.模式大多数只包含数字,我的问题是避免浮点数:
function is_id($id) {
$pattern = "/^[0-9]+/";
if(preg_match($pattern,$id)) {
echo "ok";
} else {
echo "error";
}
}
is_id(0) // error
is_id(-5) // error
is_id(-5.5) // error
is_id(1.5) // ok <-- THIS IS THE PROBLEM
is_id(10) // ok
is_id("5") // ok
is_id("string") // error
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
536 次 |
| 最近记录: |