您的位置:首页 > 其它

正则表达式限制文本框输入内容

2008-05-26 10:22 555 查看
<!--用正则表达式限制只能输入中文-->

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

<!--用正则表达式限制只能输入数字-->

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

<!--用正则表达式限制只能输入正整数-->

<input type="text" onkeyup="value=value.replace(/[^\d]/g,'').replace(/^0\d{0,4}$/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" />

<!--用正则表达式限制只能输入数字和英文-->

<input type="text" onkeyup="value=value.replace(/[\W]/g,'') " onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))" />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: