<asp:textbox onkeyup="if(isNaN(value))execCommand('undo')" runat="server"
Width="80px" onafterpaste="if(isNaN(value))execCommand('undo')"></asp:textbox>
In fact, the server control can also add onkeydown and up events.
That's all, you can enter decimals and numbers.
In .net development, in order to ensure the correctness of data, the content entered by users is often required to be verified, which is a metaphor that only numbers can be entered.
First add a property event to the TextBox control:
<asp:textbox class="Text"
onkeypress="if ( < 48 || >57) = false;"
style="TEXT-ALIGN: right" runat="server" Width="90%" MaxLength="12">
</asp:textbox>
When the keyboard is pressed, check whether the pressed 0-9 is not. If not, do not put the current input into the text box.
Note: This method controls TextBox to enter only numbers: 0~9, providing an idea
Replenish:
1. The dotted box when the cancel button is pressed
Add attribute value hideFocus or HideFocus=true in input
2. Read-only text box content
Add attribute value in input readonly
3. Prevent TEXT documents from being cleared after retreat (the style content can be used as a class reference)
<INPUT style=behavior:url(#default#savehistory); type=text id=oPersistInput>
The key moves the cursor to the next input box
<input onkeydown="if(==13)=9" >
5. Only in Chinese (with flashing)
<input onkeyup="value=(/[ -~]/g,'')" onkeydown="if(==13)=9">Use the range of Ascii code to make judgments
6. Only numbers (with flashes)
<input onkeyup="value=(/[^\d]/g,'') "onbeforepaste="('text',('text').replace(/[^\d]/g,''))">Use the range of Ascii code to make judgments
7. Only numbers (no flashing)
<input style="ime-mode:disabled" onkeydown="if(==13)=9" onKeyPress="if ((<48 || >57)) =false">Use the range of Ascii code to make judgments
8. Only enter English and numbers (with flashing)
<input onkeyup="value=(/[\W]/g,'') "onbeforepaste="('text',('text').replace(/[^\d]/g,''))">Use js regular expressions for verification
9. Blocking input method
<input type="text" name="url" style="ime-mode:disabled" onkeydown="if(==13)=9">
10. Only enter numbers, decimal points, minus signs (-) characters (no flash)
<input onKeyPress="if (!=46 && !=45 && (<48 || >57)) =false">Use the range of Ascii code to make judgments
11. Only two decimal places and three decimal places (with flash)
<input maxlength=9 onkeyup="if((/^\d{3}$/))value=(value,parseInt(value/10)) ;value=(/\.\d*\./g,'.')" onKeyPress="if((<48 || >57) && !=46 && !=45 || (/^\d{3}$/) || /\.\d{3}$/.test(value)) {=false}" id=text_kfxe name=text_kfxe> Use js regular expression for verification.
In fact, do not restrict user input in the application, just verify user input, because this restriction often brings a bad experience to people.