JS验证input输入框(字母,数目字,符号,中文)
JS验证input输入框(字母,数字,符号,中文)
js验证输入框内容 |
|
只能输入英文 |
<input type= "text" onkeyup= "value=value.replace(/[^a-zA-Z]/g,'')" >
|
|
只能输入英文 |
<input type= "text" onkeyup= "value=value.replace(/[^\a-\z\A-\Z]/g,'')"
|
onkeydown= "fncKeyStop(event)" onpaste= "return false"
|
oncontextmenu= "return false" />
|
无法粘贴,右键不会弹出粘贴菜单 |
只能输入数字: |
<input onkeyup= "this.value=this.value.replace(/\D/g,'')"
|
onafterpaste= "this.value=this.value.replace(/\D/g,'')" >
|
|
只能输入数字,小数点: |
<input name= "price" type= "text"
|
onkeyup= "value=value.replace(/[^\d\.]/g,'')" >
|
只能输入数字,小数点,下划线: |
<input name= "price" type= "text"
|
onkeyup= "value=value.replace(/[^\d\._]/g,'')" >
|
|
只能输入英文和数字: |
<input onkeyup= "value=value.replace(/[\W]/g,'') "
|
|
只能输入汉字: |
<input onkeyup= "value=value.replace(/[^\u4E00-\u9FA5]/g,'')"
|
|
禁止输入法输入: |
<input type= "text" style= "ime-mode: disabled" >
|
无法切换输入法 |
|
只能输入中文、英文、数字、@符号和.符号: |
<input type= "text"
|
onkeyup= "value=value.replace(/[^\a-\z\A-\Z0-9\u4E00-\u9FA5\@\.]/g,'')" >
|
不能为空: |
<input onblur= "if(this.value.replace(/^ +| +$/g,'')=='')alert('不能为空!')" >
|