【正則表達式】input 只能輸入漢字、數字、字母等

只能輸入漢字(有閃動):

<input type="text" id="searchStr" name="searchStr" value="請輸入姓名"
			οnkeyup="this.value=this.value.replace(/[^\u4E00-\u9FA5]/g,'')"  />

只能輸入數字(有閃動):

<input type="text" id="searchStr" name="searchStr" value="請輸入身份證號碼"
			οnkeyup="this.value=this.value.replace(/[^\d]/g,'')"  />

只能輸入漢字、字母和數字(無閃動):

			<input type="text" id="searchStr" name="searchStr" value="請輸入姓名或身份證號"
			οnkeypress="return /[\w\u4e00-\u9fa5]/.test(String.fromCharCode(window.event.keyCode))"   
      		οnpaste="return !/[^\w\u4e00-\u9fa5]/g.test(window.clipboardData.getData('Text'))"   
      		οndragenter="return false"/>



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章