正则表达式的使用

1、只能输入数字

<input  type="number" min="0"onkeyup="this.value=this.value.replace(/\D/g,'')"
                             onblur="this.value=this.value.replace(/\D/g,'')"
                             onafterpaste="this.value=this.value.replace(/\D/g,'')">
2、只能输入数字和小数点

<input  type="number" min="0" <span style="font-family: Arial, Helvetica, sans-serif;">t_value="" o_value="" </span><span style="font-family: Arial, Helvetica, sans-serif;">onkeypress="if(!this.value.match(/^[\+\-]?\d*?\.?\d*?$/))this.value=this.t_value;else this.t_value=this.value;if(this.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?)?$/))this.o_value=this.value"</span><pre name="code" class="html"><span style="white-space:pre">						</span>onblur="if(!this.value.match(/^[\+\-]?\d*?\.?\d*?$/))this.value=this.t_value;else this.t_value=this.value;if(this.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?)?$/))this.o_value=this.value"
                                                onkeyup="if(!this.value.match(/^[\+\-]?\d*?\.?\d*?$/))this.value=this.t_value;else this.t_value=this.value;if(this.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?)?$/))this.o_value=this.value"
                                                onafterpaste="if(!this.value.match(/^[\+\-]?\d*?\.?\d*?$/))this.value=this.t_value;else this.t_value=this.value;if(this.value.match(/^(?:[\+\-]?\d+(?:\.\d+)?)?$/))this.o_value=this.value"

 
 

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