1.只能輸入英文
<input type="text" onkeyup="value=value.replace(/[^a-zA-Z]/g,'')">
2.只能輸入英文
<input type="text" onkeyup="value=value.replace(/[^\a-\z\A-\Z]/g,'')" onkeydown="fncKeyStop(event)" onpaste="return false" oncontextmenu="return false" />
3.只能輸入數字:
<input onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
4.只能輸入數字,小數點:
<input name="price" type="text" onkeyup="value=value.replace(/[^\d\.]/g,'')">
5.只能輸入數字,小數點,下划線:
<input name="price" type="text" onkeyup="value=value.replace(/[^\d\._]/g,'')">
6.只能輸入英文和數字:
<input onkeyup="value=value.replace(/[\W]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
7.只能輸入漢字:
<input onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))">
8.禁止輸入法輸入:
<input type="text" style="ime-mode: disabled">
9.只能輸入中文、英文、數字、@符號和.符號:
<input type="text" onkeyup="value=value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\@\.]/g,'')">
10.不能為空:
<input onblur="if(this.value.replace(/^ +| +$/g,'')=='')alert('不能為空!')">