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