「正则表达式」input 只能输入汉字、数字、字母等

只能输入汉字(有闪动):

  1. onkeyup="this.value=this.value.replace(/[^\\u4E00-\\u9FA5]/g,'')" />

只能输入数字(有闪动):

  1. onkeyup="this.value=this.value.replace(/[^\d]/g,'')" />

只能输入汉字、字母和数字(无闪动):

  1. onkeypress="return /[\w\\u4e00-\\u9fa5]/.test(String.fromCharCode(window.event.keyCode))"
  2. onpaste="return !/[^\w\\u4e00-\\u9fa5]/g.test(window.clipboardData.getData('Text'))"
  3. ondragenter="return false"/>


分享到:


相關文章: