1.只能输入数字和英文的:
<input onkeyup="value=value.replace(/[W]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,''))">
2.只能输入数字的:
<input onkeyup="value=value.replace(/[^d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^d]/g,''))">
3.只能输入全角的:
<input onkeyup="value=value.replace(/[^uFF00-uFFFF]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^uFF00-uFFFF]/g,''))">
4.只能输入汉字的:
<input onkeyup="value=value.replace(/[^u4E00-u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^u4E00-u9FA5]/g,''))">
也可以这样:
<input type=text name= caolig value ="" onblur="if (!(/^[d]+.?d*$/.test(this.value)) ){alert('您的输入有误'); this.value='';this.focus();}">