鍍金池/ 問(wèn)答/HTML5  HTML/ 這段input只能輸入正整數(shù)的正則方法 好像不管用

這段input只能輸入正整數(shù)的正則方法 好像不管用

<input type="text" onkeyup="this.value=this.value.replace(/\D/g,'')" onpaste="return false;"></input>

有時(shí)候有用,有時(shí)候不管用

回答
編輯回答
撿肥皂

利用正則工具M(jìn)Tracer ^d+$ 可以匹配多個(gè)正整數(shù)
圖片描述
因此,替換一下正則表達(dá)式即可
oninput="this.value=this.value.replace(/^d+$/,'')"

2017年3月26日 03:52
編輯回答
影魅
<input type="text" oninput="javascript:this.value=this.value.replace(/[^\d]/g,'')" onpaste="return false;"/>
2017年9月2日 23:31
編輯回答
寫(xiě)榮
<input type="text" oninput="this.value=this.value.replace(/\D/g,'')" onpaste="return false;"></input>
2017年1月7日 02:10