JS limit input can only input numbers, letters and Chinese characters and so _javascript skills

Source: Internet
Author: User
Copy Code code as follows:

<input type= "text" onkeyup= "This.value=this.value.replace (/[^\.\d]/g,"); if (This.value.split ('. '). LENGTH>2) {this.value=this.value.split ('. ') [0]+ '.] +this.value.split ('. ') [1]} " >

1. Text box can only enter a numeric code (decimal point can not enter)
Copy Code code as follows:

<inputōnkeyup= "This.value=this.value.replace (/\d/g, '") "ōnafterpaste=" This.value=this.value.replace (/\D/g, ') ' >

2. Only numbers can be entered and the decimal point may be lost.
Copy Code code as follows:

<inputōnkeyup= ' if (isNaN (value)) ExecCommand (' Undo ') ' ōnafterpaste= ' if (isNaN (value)) ExecCommand (' Undo ') >
<input name=txt1ōnchange= "if (/\d/.test (this.value)) {alert (' can only enter a number '); this.value= ';} ' >

3. Number and decimal method two
Copy Code code as follows:

<input type=text t_value= "" o_value= "" ōnkeypress= "if!this.value.match (/^[\+\-]?\d*?\.? \d*?$/)) this.value=this.t_value;elsethis.t_value=this.value;if (This.value.match/^ (?: [\+\-]?\d+ (?: \. \d+)? $/)) This.o_value=this.value "ōnkeyup=" if (!this.value.match/^[\+\-]?\d*?\.? \d*?$/)) this.value=this.t_value;elsethis.t_value=this.value;if (This.value.match/^ (?: [\+\-]?\d+ (?: \. \d+)? $/)) This.o_value=this.value "ōnblur=" if (!this.value.match (?: [/^ (?: \. \d+)? | \.\d*?)? $/)) this.value=this.o_value;else{if (This.value.match (/^\.\d+$/)) this.value=0+this.value;if (This.value.match (/^ \.$/)) This.value=0;this.o_value=this.value} ">

4. Only letters and characters can be entered
Copy Code code as follows:

<inputōnkeyup= "Value=value.replace (/[\d]/g, '") "onbeforepaste=" Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[\d]/g, ' ")" maxlength=10 name= "Numbers" >

5. Can only enter English letters and numbers, can not enter Chinese
Copy Code code as follows:

<inputōnkeyup= "Value=value.replace (/[^\w\.\/]/ig,") ">

6. Only numbers and English can be entered
Copy Code code as follows:

<inputōnkeyup= "Value=value.replace (/[^\d|chun]/g,") ">

7. Only a maximum of two digits after the decimal point (number, Chinese can be entered), can not enter letters and operational symbols:
Copy Code code as follows:

<inputōnkeypress= "If" (event.keycode<48 | | event.keycode>57) &&event.keycode!=46 | | /\.\d\d$/.test (value)) Event.returnvalue=false ">

8. After the decimal point can only have up to two digits (numbers, letters, Chinese can be entered), you can enter operational symbols:
Copy Code code as follows:

<inputōnkeyup= "This.value=this.value.replace (/^ (\-) * (\d+) \. ( \d\d). *$/, ' $1$2.$3 ') >

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.