input中只能輸入數字

感覺這個做的比較好:

1只能輸入正整數的:
<input class="textinput" type="text" name="bjdj" value="" maxlength="10"
onkeyup="value=value.replace(/[^(/d)]/g,'') " onfocus="this.select()"onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^(/d)]/g,''))"/>


2 只能輸入數值類型的,包括小數
<input class="textinput" type="text" name="bjdj" value="" maxlength="10"
onkeyup="value=value.replace(/[^(/d|/.)]/g,'') " onfocus="this.select()"onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^(/d|/.)]/g,''))"/>

其實上面差異不大,就是將第一個在正則表達式驗證上加上了去除掉小數點驗證。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章