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