如何检查文本框是否为空并且值小于500
我有一个文本框是用户输入数字的可选字段。 如果在那里有一个号码,我想检查一下,确保它小于500,然后用它做点什么。
这是我目前正在做的事情:
if($textbox!="" && <=500)
{
//action here
}
我尝试使用andif替换&&但仍然出现错误解析错误:语法错误,意外的T_IS_SMALLER_OR_EQUAL
最简单的方法是什么?
你需要在这两个语句中使用变量preg_match('/ d /',$ textbox)== 1将确保它是一个int
if($textbox!="" && $textbox <= 500 && preg_match('/d/', $textbox ) == 1)
{
//action here
}
你错过了小于左边的部分
if($textbox!="" && $textbox <=500)
{
//action here
}
链接地址: http://www.djcxy.com/p/12035.html
上一篇: How to check if a text box is not empty and the value is less than 500