Fork me on GitHub

JS只能输入数字,数字和字母等的正则表达式

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,'')">

 

posted @ 2016-01-02 11:21  磊哥|www.javacn.site  阅读(13581)  评论(0编辑  收藏  举报