我有這個inupt領域檢查用戶只輸入數字,PHP
<p style="font-size: 18px;">Total Bids: <input type="text" class="total_bids" name="total_bids" placeholder="No. of Bids"></p>
通過獲取其值:
var totalbids = document.getElementsByName('total_bids')[0].value;
,並通過
$total_bids = PSF::requestGetPOST('totalbids');
一切都讓PHP中的價值工作正常,但它應該只取數值,所以我試圖檢查用戶是否只輸入一個數字,如何定義字母範圍s但願我可以設置檢查類似
if($total_bids== 'alphabet range')
{
return json_encode(array('error' => 'Please enter a valid Number.'));
}
'如果(is_numeric($ numberOrLetters)){...}'??? [php.net文檔](http://php.net/manual/en/function.is-numeric.php) –
這裏是你回答:http://stackoverflow.com/questions/13779209/checking-that-a -value-contains-only-digits-regex-or-no – swidmann