input文本框输入限制(正则表达式)

1、只能输入纯数字:

<input type='text' onkeyup="this.value=this.value.replace(/[^0-9-]+/,'');" />

2、只能输入数字和小数点

<input onkeyup="value=value.replace(/[^\d\.]/g,'')" onblur="value=value.replace(/[^\d\.]/g,'')"/>

3、只能输入数字和字母

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

posted @ 2018-11-14 11:37  苹果的味道_Echo  阅读(5458)  评论(0编辑  收藏  举报