作者Clessin (Clemond)
看板PHP
標題Re: [請益] 表單文字方塊
時間Wed Jan 11 17:56:39 2006
※ 引述《gckenny (絕体絕命!小君君的最期~)》之銘言:
: <script type="text/javascript">
: function check_num()
: {
: if ((/\D/.test(document.getElementById('num').value)) ||
: ((document.getElementById('num').value).length > 1))
: {
: alert("請輸入單一數字!");
: document.getElementById('num').focus();
: return false;
: }
: }
: </script>
: <input type="text" id="num" onblur="check_num()" />
可是若使用者輸入的是一個字母(a-z)怎麼辦呢?它的lendth不也是1嗎?原問不是只要
使用者輸入1個數字嗎?
觀念有誤請指教...
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.138.74.203
推 gckenny:這有限制不能輸入數字以外的字元(包含英文字母) 01/11 18:00
推 alpe:reg exp \D = [^0-9] 不是數字的字元 01/11 18:50