JS limit input can only enter numbers, letters and Chinese characters, etc.

Source: Internet
Author: User
Tags split

 js Limit input can only enter the number of decimal points can not enter or can only enter a number, can lose a decimal point and so on, this article is roughly sorted out some of the friends interested can be collected under

The code is 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 boxes can only enter numeric codes (decimal points cannot be entered)   code is 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, the decimal point .  code is 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. Numbers and decimal methods two   code is 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 (/^ (?: [+-]?d+ (?:. 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 the letters and Chinese characters   code can be entered 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 is as follows: < Inputōnkeyup= "Value=value.replace (/[^w./]/ig,") ">    6. Only the numbers and the English   code can be entered as follows: <inputōnkeyup=" Value=value.replace (/[^d|chun]/g, ' ")" >    7. Only a maximum of two digits after a decimal point (number, Chinese can enter), cannot enter the letter and the operation symbol:  code is as follows: < Inputōnkeypress= "If" (event.keycode<48 | | event.keycode>57) &&event.keycode!=46 | | /.dd$/.test (value)) Event.returnvalue=false ">    8. Only a maximum of two digits (digits, letters, and Chinese input) can be entered after the decimal point, and the operation symbol:  code is as follows: <inputōnkeyup= "This.value=this.value.replace (/^ (-) * (d+). (DD). *$/, ' $1$2.$3 ' ">   
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.