JS只能輸入數字,數字和字母等的正規表示式

王磊的部落格發表於2016-01-02

1.只能輸入英文
  <input type="text" onkeyup="value=value.replace(/[^a-zA-Z]/g,'')">

 

2.只能輸入中文、英文、數字、@符號和.符號

  <input type="text" onkeyup="value=value.replace(/[^a-za-z0-9u4e00-u9fa5@.]/g,'')">

 

3.只能輸入字母和漢字
  <input onkeyup="value=value.replace(/[d]/g,'') "onbeforepaste="clipboarddata.setdata('text',clipboarddata.getdata('text').replace(/[d]/g,''))" maxlength=10 name="numbers">

 

 

4.只能輸入英文字母和數字,不能輸入中文
  <input onkeyup="value=value.replace(/[^\w\/]/ig,'')"> 

 


5.只能輸入英文字母和數字,不能輸入中文
  <input onkeyup="value=value.replace(/[^\w\.\/]/ig,'')">

 

相關文章