Restrict input format: Enter only numbers

Source: Internet
Author: User

1. Only enter and paste numbers

<input onkeyup= "This.value=this.value.replace (/\d/g, ')" onafterpaste= "This.value=this.value.replace (/\D/g, ' ) "/>

2. Only numbers can be entered
<input onkeyup= "if (/\d/.test (this.value)) {alert (' Input number only '); this.value= ' 0 ';}" >

3. Only enter numbers and English
<input onkeyup= "Value=value.replace (/[\w]/g, ')"
Onbeforepaste= "Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^\d]/g, ')" ><br/ >

4. Enter only numbers and decimal points
<input onkeyup= "Value=value.replace (/[^\d{1,}\.\d{1,}|\d{1,}]/g, ')"/><br/>

5. Only numbers and "-"
<input onkeyup= "Value=value.replace (/[^\w&=]|_/ig, ')" onblur= "Value=value.replace (/[^\w&-]|_/ig, ')" />

6. Prohibit input of Chinese characters
<input style= "ime-mode:disabled" > IME does not convert, but can be pasted on <br/>

7. Only import and paste Chinese characters
<input onkeyup= "Value=value.replace (/[^\u4e00-\u9fa5]/g, ')"
Onbeforepaste= "Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^\u4e00-\u9fa5]/g, ')" ><br/>

Restrict input format: Enter only numbers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.