JavaScript numeric character validation regular code

Source: Internet
Author: User
Tags numeric

<input type= "text" name= "TextField" onkeypress= "Javascript:alert (Event.keycode); return flase" >
1. Text box can only enter a numeric code (decimal point can not enter)
<input onkeyup= "This.value=this.value.replace (/d/g,") "Onafterpaste=" This.value=this.value.replace (/D/g, "") " >
2. Only numbers can be entered and the decimal point may be lost.
<input onkeyup= "if (isNaN (value)) ExecCommand (' Undo ') ' onafterpaste= ' if (isNaN (value)) ExecCommand (' Undo ') >
<input name=txt1 onchange= "if (/d/.test (this.value)) {alert (' can only enter numbers '); this.value= ';} ' >
3. Number and decimal method two
<input type=text t_value= "" o_value= "" onkeypress= "if!this.value.match (/^[+-]?d*?.? d*?$/)) This.value=this.t_value;else this.t_value=this.value;if (This.value.match/^ (?: [+-]?d+ (?:. d+)?)? $/)) This.o_value=this.value "onkeyup=" if (!this.value.match (/^[+-]?d*?.? d*?$/)) This.value=this.t_value;else this.t_value=this.value;if (This.value.match/^ (?: [+-]?d+ (?:. d+)?)? $/)) This.o_value=this.value "onblur=" 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 letters and characters can be entered
<input onkeyup= "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
<input onkeyup= "Value=value.replace (/[^w./]/ig, ')" >
6. Only digital and English <font color= "Red" >chun</font>
<input onkeyup= "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:
<input onkeypress= "If" (event.keycode<48 | | event.keycode>57) && event.keycode!=46 | |/.dd$/.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:
<input onkeyup= "This.value=this.value.replace (/^ (-) * (d+). ( DD). *$/, ' $1$2.$3 ' >
<input onkeyup= "Value=value.replace (/[^d.] /g, ') ' >
<input type=text onkeypress= "return event.keycode>=65" style= "ime-mode:disabled" >
<input type=text t_value= "" o_value= "" onkeypress= "if!this.value.match (/^[+-]?d*?.? d*?$/)) This.value=this.t_value;else this.t_value=this.value;if (This.value.match/^ (?: [+-]?d+ (?:. d+)?)? $/)) This.o_value=this.value "onkeyup=" if (!this.value.match (/^[+-]?d*?.? d*?$/)) This.value=this.t_value;else this.t_value=this.value;if (This.value.match/^ (?: [+-]?d+ (?:. d+)?)? $/)) This.o_value=this.value "onblur=" 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} ">
<input onkeyup= "This.value=this.value.replace (/d/g,") "Onafterpaste=" This.value=this.value.replace (/D/g, "") " >
Or
<input name=txt1 onchange= "if (/d/.test (this.value)) {alert (' can only enter numbers '); this.value= ';} ' >
Or
<input onkeyup= "if (isNaN (value)) ExecCommand (' Undo ') ' onafterpaste= ' if (isNaN (value)) ExecCommand (' Undo ') >

Restrict text boxes to only enter numbers including decimal points
<input onkeyup= "Value=value.replace (/[^d.] /g, ') ' >
About regular expression 1. Only numbers and English can be entered: <input onkeyup= "Value=value.replace (/[w]/g,") "Onbeforepaste=" Clipboarddata.setdata (' Text ', Clipboarddata.getdata (' text '). Replace (/[^d]/g, ') "id=" Text1 "name=" Text1 ">
2. Only numbers can be entered: <input onkeyup= "Value=value.replace (/[^d]/g,") "Onbeforepaste=" Clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[^d]/g, ') "id=" Text2 "name=" Text2 ">
3. Only the full angle can be entered: <input onkeyup= "Value=value.replace (/[^uff00-uffff]/g,") "Onbeforepaste=" Clipboarddata.setdata (' Text ', Clipboarddata.getdata (' text '). Replace (/[^uff00-uffff]/g, ') "id=" Text3 "name=" Text3 ">
4. Only Chinese characters can be entered: <input onkeyup= "Value=value.replace (/[^u4e00-u9fa5]/g,") "Onbeforepaste=" Clipboarddata.setdata (' Text ', Clipboarddata.getdata (' text '). Replace (/[^u4e00-u9fa5]/g, ') "id=" Text4 "name=" TEXT4 ">
When you move to an input box, it is automatically selected: <input type= "text" id= "Text1" name= "Text1" value= "input retrieves the keyword" onclick= "Javascript:this.form.text1.focus ( ); This.form.text1.select (); "Maxlength="/>

Related Article

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.