Code (Text in IE6, ie9, Mac, Google Crome):
$ (Function (){
$ ("# <% = Txtitem. clientid %>"). keydown (function (e ){
// Do not use the keypress method here. Otherwise, CTRL + V and CTRL + V cannot be disabled. for specific reasons, identify the keypress and keydown. This is very important. Please refer to it for details.
If ($. browser. MSIE ){// Judge the browser
If (event. keycode> 47) & (event. keycode <58) | (event. keycode = 8 )){// Judge the key value
Return true;
} Else {
Return false;
}
} Else {
If (E. which> 47) & (E. which <58) | (E. which = 8) | (event. keycode = 17 )){
Return true;
} Else {
Return false;
}
}). Focus (function (){
This. style. imemode = 'Disabled ';// Disable the input method. Do not enter Chinese characters.
});
});
// Remarks:
// Imemode has four forms:
// Active indicates that the input method is Chinese.
// Inactive indicates that the input method is English
// Auto indicates that the input method is enabled (default)
// Disable indicates that the input method is disabled.
Colleagues' collection practices:
1. Regular Expressions limit float :( ^ [0-9] ([.] [0-9] {1, 2 })? $) | (^ 1 [0-9] ([.] [0-9] {1, 2 })? $) | (^ 2 [0-3] ([.] [0-9] {1, 2 })? $) | (^ 24 ([.] 0 {1, 2 })? $)
2. Restrict Input
Function keypress (objtr) {// only data characters 0-9 and decimal point can be entered
// Var objtr = element.doc ument. activeelement;
VaR txtval = objtr. value;
Var key = event. keycode;
If (Key <48 | key> 57) & Key! = 46 ){
Event. keycode = 0;
Alert ("only numbers allowed ");
}
Else {
If (Key = 46 ){
If (txtval. indexof (".")! =-1 | txtval. Length = 0)
Event. keycode = 0;
}
}
}
3. Do not switch the Input Method
Style: "ime-mode: Disabled"