This article is reproduced to: js restricts the input box to only enter numbers , and thanks the original author for the arrangement and creation;
1. Restrict the input box to only enter numbers:
<input type="text" name="Only_Number" onkeyup="this.value=this.value.replace(/[^\d]/g,'') " onafterpaste="this.value=this.value.replace(/[^\d]/g,'') " />
2. The input box can only enter regular expressions of letters and underscores:
<input onkeyup="this.value=this.value.replace(/[^_a-zA-Z]/g,'')" onpaste="this.value=this.value.replace(/[^_a-zA-Z]/g,'')" />
3. The input box can only enter regular expressions of alphanumerics and underscores:
<input onkeyup="this.value=this.value.replace(/[^\w]/g,'')" onpaste="this.value=this.value.replace(/[^\w]/g,'')" />
<!-- 或者 -->
<input onkeyup="this.value=this.value.replace(/[\W]/g,'')" onpaste="this.value=this.value.replace(/[\W]/g,'')" />