JS code restricts the input box to only enter numbers

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,'')" />

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326544045&siteId=291194637