使用正则判断用户输入是否是数字

时间:2024-10-14 20:46:08

1、JavaScript code?functionche罕铞泱殳ck(){varreg=/^[0-9]*$/;vartextBox=document.getElementById("<%=TextBox4.ClientID%>").value;

使用正则判断用户输入是否是数字

2、 if(!reg.test(textBox)){alert("必须输入数字!");document.getElementById("<%=TextBox4.ClientID%>").focus();returnfalse;}returntrue;}

使用正则判断用户输入是否是数字

3、^[1-9]d*$  //匹配正整数^-[1-9]d*$ //匹配负整数

使用正则判断用户输入是否是数字

4、^-?[1-9]d*$  //匹配整数^[1-9]d*|0$ //匹配非负整数(正整数+0)^-[1-9]d*|0$  //匹配非正整数(负整数+0)

使用正则判断用户输入是否是数字

5、^[1-9]d*.d*|0.d*[1-9]d*$  //匹配正浮点数^-([1-9]d*.d*|0.d*[1-9]d*)$ //匹配负浮点数^-?([1-9]d*.d*|0.d*[1-9]d*|0?.0+|0)$ //匹配浮点数

使用正则判断用户输入是否是数字

6、^[1-9]d*.d*|0.d*[1-9]d*|0?.0+|0$  //匹配非负浮点数(正浮点数+0)^(-([1-9]d*.d*|0.d*[1-9]d*))|0?.0+|0$  //匹配非正浮点数(负浮点数+0)BTY:处理大量数据时有用,具体应用时注意修正

使用正则判断用户输入是否是数字
© 手抄报圈