Js controls input character resolution

  • 2020-03-30 01:06:30
  • OfStack

The ENTER key moves the cursor to the next input field
< Input onkeydown = "if (event. KeyCode = = 13) event. The keyCode = 9" >

Only in Chinese
< Input onkeyup = "value = value. The replace (/ [to] / g,") "onkeydown =" if (event. KeyCode = = 13) event. KeyCode = 9 ">

Shielded input method
< Input style = "ime - mode: disabled" onkeydown = "if (event. KeyCode = = 13) event. KeyCode = 9" >

Input English and Numbers only
< Input onkeyup = "value = value. The replace (/ [/ W] / g,") "onbeforepaste =" clipboardData. SetData (' text 'clipboardData. GetData (' text'). The replace (/ [^ \] d/g, ")) "onkeydown =" if (event. KeyCode = = 13) event. KeyCode = 9 ">

It can only be Numbers
< Input onkeyup = "value = value. The replace (/ [^ \] d/g,") "onbeforepaste =" clipboardData. SetData (' text 'clipboardData. GetData (' text'). The replace (/ [^ \] d/g, ")) ">

It can only be displayed, not modified
< Input readonly value=" display only ">

Enter only Numbers to determine the value of the key


<script   language=javascript>
function   onlyNum()
{
if(!((event.keyCode>=48&&event.keyCode<=57)||(event.keyCode>=96&&event.keyCode<=105)||(event.keyCode==8)))
event.returnValue=false;
}
</script>
<input   onkeydown="onlyNum();">

1. Text box can only enter numeric code (decimal point can not enter)
< Input onkeyup = "this value = this. The value, the replace (\ D/g,") "onafterpaste =". This value = this. The value, the replace (\ D/g, ") ">

2. Can only input Numbers, can input decimal points.
< Input onkeyup = "if (isNaN (value)) execCommand (' undo ')" onafterpaste = "if (isNaN (value)) execCommand (' undo ')" >
< Input name=txt1 onchange="if(/\D/.test(this.value)){alert(' number only '); This. Value = ' '; } ">

3. Number and decimal point method two
< Input type=text t_value="" o_value="" onkeypress="if(! Enclosing the value. The match (/ ^ [\ + \]? \ d *? \.? \ d *? $/)). This value = this. T_value; Value; else enclosing t_value = this. If (this. Value. The match (/ ^ (? : [\ + \]? \ d + (? : \ \ d +)? ? $/)) enclosing o_value = this. The value "onkeyup =" if (! Enclosing the value. The match (/ ^ [\ + \]? \ d *? \.? \ d *? $/)). This value = this. T_value; Value; else enclosing t_value = this. If (this. Value. The match (/ ^ (? : [\ + \]? \ d + (? : \ \ d +)? ? $/)) enclosing o_value = this. The value "onblur =" if (! This. The value. The match (/ ^ (? : [\ + \]? \ d + (? : \ \ d +)? . | \ \ d *? ? $/)). This value = this. O_value; Else {the if (this. Value. The match (/ ^ \ \ d + $/)). This value = 0 + enclosing the value; If (this. Value. The match (/ ^ \. $/)). This value = 0; Enclosing o_value = this. Value} ">

4. Only input letters and Chinese characters
< Onkeyup ="value=value.replace(/[\d]/g, ")" onbeforepaste=" clipboarddata.setdata ('text', clipboarddata.getdata ('text'). Replace (/[\d]/g,'))" maxlength=10 name="Numbers">

5. Input English letters and Numbers only, not Chinese
< Input onkeyup = "value = value. The replace (/ [^ \ w \ \] / ig,") ">

6. Enter only Numbers and English. Font color = "Red" > Chun< / font>
< Input onKeyUp = "value = value. The replace (/ [^ \ | d chun] / g,") ">

7. No more than two digits can be entered after the decimal point. No more letters or operational symbols can be entered:
< Input onKeyPress = "if ((event. KeyCode< 48 | | event. KeyCode> 57) && event keyCode! = 46 | | / \ \ d \ d $/ test (value)) event. ReturnValue = false ">

8. There can be no more than two digits after the decimal point (digits, letters and Chinese characters can be input). Operation symbols can be input:
< Input onkeyup = "this value = this. The value, the replace (/ ^ (\ -) * (\ d +) \. (\ d \ d). * $/, '$1 $2. $3)" >

It can only be Numbers and decimal points and add, subtract and multiply


Only Numbers, decimal points and negative Numbers can be entered


<input name="input" type="text" onkeyup="JHshNumberText(this)" id="title">
<script language="javascript" type="text/javascript">
function JHshNumberText(a)
{ 
var fa="";
if(a.value.substring(0,1)=="-")
      fa="-";
var str=(a.value.replace(/[^0-9.]/g,'')).replace(/[.][0-9]*[.]/, '.');
if (str.substring(0,1)==".")
   str="0"+str;
   a.value=fa+str;
} 
</script>

1. Cancel the dotted box when the button is pressed, and add the attribute value hideFocus or hideFocus =true in the input
< Input type="submit" value=" submit" hidefocus="true" />

2. Readonly the text box content and add the attribute value readonly in the input
< Input type = "text" readonly / >

3. Prevent backout of empty TEXT documents (you can do the style content as a class reference)
< Input type = "text" style = "behaviors: url (# default# savehistory);" / >

4. The ENTER key moves the cursor to the next input field
< Input type = "text" onkeydown = "if (event. KeyCode = = 13) event. KeyCode = 9" / >

5. Chinese only (flashing)
< Input type="text" onkeyup="value=value.replace(/[-~]/g, ")" onkeydown="if(event.keycode ==13) event.keycode =9" />

6. Only Numbers (flashing)
< Input type="text" onkeyup="value=value.replace(/[^\d]/g, ")" onbeforepaste=" clipboarddata.setdata ('text', clipboarddata.getdata ('text').

7. Number only (no flashing)
< Input type="text" style="ime-mode:disabled" onkeydown="if(event.keycode ==13) event.keycode =9" onkeypress="if ((event.keycode< 48 | | event. KeyCode> 57)) event. ReturnValue = false "/ >

8. Input English and Numbers only (flashing)
< Input type="text" onkeyup="value=value.replace(/[\W]/g, ")" onbeforepaste=" clipboarddata.setdata ('text', clipboarddata.getdata ('text').

9. Block the input method
< Input type="text" name="url" style="ime-mode:disabled" onkeydown="if(event.keycode ==13) event.keycode =9" />

10. Can only input Numbers, decimal points, minus (-) characters (no flashing)
< Input onkeypress = "if (event keyCode! = 46 && event keyCode! = 45 && (event. KeyCode< 48 | | event. KeyCode> 57)) event. ReturnValue = false "/ >

11. Can only input two decimal places, three decimal places (with flashing)
< Input type="text" maxlength="9" onkeyup="if(value.match(/^\d{3}$/)))value=value.replace(value,parseInt(value/10)); Value = value. The replace (/ \ \ d * \. / g, '. ') "onkeypress =" if ((event. KeyCode< 48 | | event. KeyCode> 57) && event keyCode! = 46 && event keyCode! = 45 | | value. The match (/ ^ \ d {3} $/) | | / \ \ d {3} $/. The test (value)) {event. ReturnValue = false} "/ >


Related articles: