JS驗證input輸入框(字母,數字,符號,中文)

JS驗證input輸入框(字母,數字,符號,中文)this

js驗證輸入框內容

只能輸入英文spa

<input type="text" onkeyup="value=value.replace(/[^a-zA-Z]/g,'')">

只能輸入英文code

<input type="text" onkeyup="value=value.replace(/[^\a-\z\A-\Z]/g,'')"
onkeydown="fncKeyStop(event)" onpaste="return false"
oncontextmenu="return false" />

沒法粘貼,右鍵不會彈出粘貼菜單

只能輸入數字:blog

<input onkeyup="this.value=this.value.replace(/\D/g,'')"
onafterpaste="this.value=this.value.replace(/\D/g,'')">

只能輸入數字,小數點:ip

<input name="price" type="text"
onkeyup="value=value.replace(/[^\d\.]/g,'')">


只能輸入數字,小數點,下劃線:get

<input name="price" type="text"
onkeyup="value=value.replace(/[^\d\._]/g,'')">

 

只能輸入英文和數字:input

<input onkeyup="value=value.replace(/[\W]/g,'') "
onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">


只能輸入漢字:it

<input onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')"
onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))">


禁止輸入法輸入:event

<input type="text" style="ime-mode: disabled">

沒法切換輸入法ast

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

<input type="text"
onkeyup="value=value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\@\.]/g,'')">


不能爲空:

<input onblur="if(this.value.replace(/^ +| +$/g,'')=='')alert('不能爲空!')">


轉自互聯網:JS驗證input輸入框(字母,數字,符號,中文)

相關文章
相關標籤/搜索