What is the meaning of input type and how to limit input

Time:2021-1-25

Common methods of limiting input
1. Cancel the dotted box when the button is pressed, and add the attribute value hidefocus or hidefocus = true in input

Copy code

The code is as follows:

< input type = submit “value = submit” hideocus = true / >

2. Read only text box content, add attribute value readonly in input

Copy code

The code is as follows:

<input type=”text” readonly />

3. Prevent text documents from being emptied backward (style content can be used as class reference)

Copy code

The code is as follows:

<input type=”text” style=”behavior:url(#default#savehistory);” />

4. Enter key can move the cursor to the next input box

Copy code

The code is as follows:

<input type=”text” onkeydown=”if(event.keyCode==13)event.keyCode=9″ />

5. Chinese only (with flashing)

Copy code

The code is as follows:

<input type=”text” onkeyup=”value=value.replace(/[ -~]/g,”)” onkeydown=”if(event.keyCode==13)event.keyCode=9″ />

6. Only numbers (flashing)

Copy code

The code is as follows:

<input type=”text” onkeyup=”value=value.replace(/[^\d]/g,”) ” onbeforepaste=”clipboardData.setData(‘text’,clipboardData.getData(‘text’).replace(/[^\d]/g,”))” />

7. Only numbers (no flashing)

Copy code

The code is as follows:

<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. Only English and numbers can be input (with flashing)

Copy code

The code is as follows:

<input type=”text” onkeyup=”value=value.replace(/[\W]/g,”)” onbeforepaste=”clipboardData.setData(‘text’,clipboardData.getData(‘text’).replace(/[^\d]/g,”))” />

9. Shielded input method

Copy code

The code is as follows:

<input type=”text” name=”url” style=”ime-mode:disabled” onkeydown=”if(event.keyCode==13)event.keyCode=9″ />

10. Only number, decimal point, minus sign (-) character can be input (no flashing)

Copy code

The code is as follows:

<input onkeypress=”if (event.keyCode!=46 && event.keyCode!=45 && (event.keyCode<48 || event.keyCode>57)) event.returnValue=false” />

11. Only two decimal places and three decimal places can be input (with flashing)

Copy code

The code is as follows:

<input type=”text” maxlength=”9″ onkeyup=”if(value.match(/^\d{3}$/))value=value.replace(value,parseInt(value/10)) ;value=value.replace(/\.\d*\./g,’.’)” onkeypress=”if((event.keyCode<48 || event.keyCode>57) && event.keyCode!=46 && event.keyCode!=45 || value.match(/^\d{3}$/) || /\.\d{3}$/.test(value)) {event.returnValue=false}” />