You can enter only numbers in a text box on a webpage. + Press enter to change the tab (use of the Javascript key) + do not change the Input Method

Source: Internet
Author: User

Step 1: Use the style sheet.
<Asp: textbox id = "textbox1" runat = "server" style = "ime-mode: Disabled" onkeydown = "mykeydown ()"> </ASP: textbox>

Step 2 Use JS scripts.

<SCRIPT type = "text/JavaScript">
Function mykeydown ()
{
VaR K = Window. event. keycode;

If (k = 46) | (k = 8) | (k = 189) | (k = 109) | (k = 190) | (k = 110) | (k> = 48 & K <= 57) | (k> = 96 & K <= 105) | (k> = 37 & K <= 40 ))
{

}
Else if (k = 13)
{
Window. event. keycode = 9;
}
Else
{
Window. event. returnvalue = false;
}
}
</SCRIPT>

You can use a style sheet (style = "ime-mode: Disabled") to prevent switching to a Chinese character input method. That is to say, you can only use an English input method. This prevents Chinese characters from being entered.

JavaScript scripts are used to restrict keyboard input. Only numbers, decimal points, minus signs, backspace keys, deletion keys, and direction keys can be entered.

ASCII code description:
8: Return key
46: Delete
37-40: direction keys
48-57: number in the keypad
96-105: Number of the primary key area
110, 190: decimal point in the keypad and primary key areas
189 and 109: negative numbers in the keypad and primary key areas

13: Press ENTER
9: tab is the stuff that moves the focus to the next text box.

By the way, there are two disadvantages:
1. if multiple decimal points are not verified.
2. Multiple negative signs are not verified, and the symbols must be in the front.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.