JS can only be judged by numbers and decimal points. 1, the text box can only enter a numeric code (the decimal point cannot be entered) to copy code examples:<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 will be lost. Copy Code code example:<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 a number '); this.value= ";}">3, number and decimal method two copy Code code example:<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+)?)? $/)) 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+)?)? $/)) This.o_value=this.value"Onblur="if (!this.value.match/^ (?: [\+\-]?\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, you can only enter alphabetic and Kanji copy Code code examples:<input onkeyup="Value=value.replace (/[\d]/g, ")"Onbeforepaste="clipboarddata.setdata (' text ', Clipboarddata.getdata (' text '). Replace (/[\d]/g, ")"Maxlength=TenName="Numbers">5, you can only enter English letters and numbers, you cannot enter the Chinese copy Code code example:<input onkeyup="Value=value.replace (/[^\w\.\/]/ig, ")">6, only numbers and English <font can be entered color="Red">chun</font>Copy Code code example:<input onkeyup="Value=value.replace (/[^\d|chun]/g, ")">7, you can only have up to two digits after the decimal point (numbers, Chinese can be entered), you cannot enter letters and arithmetic symbols: Copy code example:<input onkeypress="if ((event.keycode<48 | | event.keycode>57) && event.keycode!=46 | |/\.\d\d$/.test (value)) Event.returnvalue=false">8, only a maximum of two digits after the decimal point (numbers, letters, Chinese can be entered), you can enter the operation symbol: Copy code code example:<input onkeyup="This.value=this.value.replace (/^ (\-) * (\d+) \. ( \d\d). *$/, ' $1$2.$3 ')">can only be numeric and decimal and plus minus multiply the code code example: onkeypress="return event.keycode>=4&&event.keycode<=57"This article original link: http://www.jbxue.com/article/15871.html
JS Limit text box input can only enter a number