This article is a mirror article of machine translation, please click here to jump to the original article.

View: 15458|Reply: 0

[ASP.NET] Asp.net TextBox can only enter numbers

[Copy link]
Posted on 3/27/2015 3:45:42 PM | | |

<asp:textbox id="TextBox1" runat="server"

Width="80px"></asp:textbox>

In fact, server controls can also add onkeydown and up events

In this way, you can only enter decimals and numbers



In .NET development, in order to ensure the correctness of data, users are often required to verify the content they enter, figuratively speaking, only numbers can be entered.

Start by adding a property event to the TextBox control:

<asp:textbox class="Text"

        onkeypress="if (event.keyCode < 48 || event.keyCode >57) event.returnValue = false; "

id="txtY_Revenue" style="TEXT-ALIGN: right" runat="server" Width="90%" MaxLength="12">

    </asp:textbox>

The keyboard checks when pressed to see if it is 0-9, if not, does not put the current input into the text box

Note: This method controls the TextBox to enter only numbers: 0~9, providing an idea

Supplement:

1. Cancel the dotted box when the button is pressed



Add the attribute value hideFocus or HideFocus=true to the input

2. Read only the text box content



Add the attribute value readonly to the input

3. Prevent TEXT documents from being cleared back (style content can be used as a class reference)



<INPUT style=behavior:url(#default#savehistory); type=text id=oPersistInput>

4. ENTER key to move the cursor to the next input box

<input >

5. Only in Chinese (with flashing)

<input>Use the range of Ascii codes to judge

6. Only for numbers (with flashing)

<inputonbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" > use the range of the Ascii code to judge

7. Only for numbers (no flickering)

<input style="ime-mode:disabled"> use the range of Ascii code to judge

8. Only English and numbers can be entered (with flashing)



<inputonbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" > validated with js' regular expressions

9. Shield input method

<input type="text" name="url" style="ime-mode:disabled">

10. Only enter numbers, decimal points, minus (-) characters (no flashing)

<input>Use the range of Ascii codes to judge




Previous:How do I display the RadioButtonList in asp.net vertical and horizontal rows?
Next:asp.net validate mailbox format regex
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com