[摘要]只能输入中文<input type="text" onkeyup="this.value=this.value.replace(/[^\u4e00-\u9fa5]...
只能输入中文
<input type="text" onkeyup="this.value=this.value.replace(/[^\u4e00-\u9fa5]/g,'')">
只能输入英文
<input type="text" onkeyup="this.value=this.value.replace(/[^a-zA-Z]/g,'')">
文本框只能输入数字代码(小数点也不能输入)
<input onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
只能输入数字,能输小数点
方法一:<input onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')">
方法二:<input name=txt1 onchange="if(/\D/.test(this.value)){alert('只能输入数字');this.value='';}">
方法三:<input onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" onafterpaste="this.value=this.value.replace(/[^\d.]/g,'')" >
只能输入数字和英文
<input onKeyUp="value=value.replace(/[^\d
关键词:html中如何控制input输入格式的示例