我有这个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