review onkeypress in Html

only number in input
1. <input onkeypress="return (/[\d]/.test(String.fromCharCode(event.keyCode)))" style="ime-mode:Disabled">"
The ime-mode CSS property controls the state of the input method editor for text fields.  
Ref: https://developer.mozilla.org/en-US/docs/Web/CSS/ime-mode

2. <input type=text onkeypress="return test();" style="ime-mode:Disabled">
function test(){
   return /[\d]/.test(String.fromCharCode(event.keyCode));
}

3<input type=text onkeypress="test()" style="ime-mode:Disabled">
function test(){
  //if (isNaN(this.value)){ 
  window.event.returnValue=false;
  }
  
}

other:
<input name="username" type="text" onkeyup="value=value.replace(/[^\w\.\/]/ig,'')">
only letter, number, &, = and @
<input name="username" type="text" onkeyup="value=value.replace(/[^\w=@&]|_/ig,'')">
<input name="username" type="text" onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')">

REF:  blog . sina . com . cn / s /blo g_a3ca81000101azga.html

评论

此博客中的热门博文

XML, XSL, HTML

Input in element.eleme.io

Data URI是由RFC 2397 ACE