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

<!-- 用正则表达式限制只能输入中文 -->   
< 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,''))"    />

你可能感兴趣的:(正则表达式)