2012-04-13 178 views
0

我有一個文本框是用戶輸入數字的可選字段。如果在那裏有一個號碼,我想檢查一下,確保它小於500,然後用它做點什麼。如何檢查文本框是否爲空且值小於500

這是我目前在做什麼:

if($textbox!="" && <=500) 
{ 
//action here 
} 

我試着更換& &使用以及如果,但仍得到一個錯誤解析錯誤:語法錯誤,意想不到的T_IS_SMALLER_OR_EQUAL

什麼是最簡單的方法做這個?

回答

3

您需要使用的變量都聲明 的preg_match(「/ \ d /」,$文本)== 1將確保它是一個int

if($textbox!="" && $textbox <= 500 && preg_match('/\d/', $textbox) == 1) 
{ 
//action here 
} 
+0

Muchas gracias! – Ian 2012-04-13 20:46:48

+3

或者,使用'is_numeric()'http://us.php.net/manual/en/function.is-numeric.php – 2012-04-13 20:52:28

+0

非常真實,許多方法做到這一點 – squarephoenix 2012-04-13 20:53:02

0

你缺少的左側部分小於

if($textbox!="" && $textbox <=500) 
{ 
//action here 
}