Html input box verification, input box Verification
JS judgment can only be a number or a decimal point
1. Only numeric code can be entered in the text box (decimal point cannot be entered)
<Input onkeyup = "this. value = this. value. replace (/\ D/g, '')" onafterpaste = "this. value = this. value. replace (/\ D/g, '')">
2. Only numbers can be entered, and decimal points can be entered.
<Input onkeyup = "if (isNaN (value) execCommand ('undo ')" onafterpaste = "if (isNaN (value) execCommand ('undo')">
<Input name = txt1 onchange = "if (/\ D /. test (this. value) {alert ('only numbers allowed '); this. value = '';}">
3. Number and decimal point method 2
<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 (! 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. Only letters and Chinese 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. Only English letters and numbers are allowed. Chinese characters are not allowed.
<Input onkeyup = "value = value. replace (/[^ \ w \. \/]/ig,'') ">
6. Only numbers and English letters can be entered. <font color = "Red"> chun </font>
<Input onKeyUp = "value = value. replace (/[^ \ d | chun]/g,'') ">
7. After the decimal point, you can enter a maximum of two digits (numbers and Chinese characters). You cannot enter letters or operator numbers:
<Input onKeyPress = "if (event. keyCode <48 | event. keyCode> 57) & event. keyCode! = 46 |/\. \ d $/. test (value) event. returnValue = false ">
8. A maximum of two digits (numbers, letters, and Chinese characters) can be entered after the decimal point. You can enter the operator number:
<Input onkeyup = "this. value = this. value. replace (/^ (\-) * (\ d + )\. (\ d ). * $/, '$1 $2. $ 3') ">
Input Chinese characters:
<Input type = "text" onkeyup = "this. value = this. value. replace (/[^ \ u4e00-\ u9fa5]/g,'') ">
Enter a number:
<Input type = "text" onkeyup = "this. value = this. value. replace (/\ D/g,'') ">
Input English:
<Input type = "text" onkeyup = "this. value = this. value. replace (/[^ a-zA-Z]/g,'') ">
Three together
<Input onkeyup = "value = value. replace (/[^ \ w \ u4E00-\ u9FA5]/g,'') ">
Enter only numbers and letters
<INPUT class = input maxLength = 12 size = 15 name = username id = "username" onKeyUp = "value = value. replace (/[\ W]/g, '')">
Only English Punctuation Marks can be used for Chinese, English letters, numbers, and Chinese punctuation.
<Input type = "text" onkeyup = "this. value = this. value. replace (/^ [^! @ # $ % ^ & * ()-= +]/G, '')">