使用脚本: 定义一个文本框:<ASP:TextBox id=TextBox1 runat=server /> 只能输入数字的脚本如下: <script language="vbscript"> Sub TextBox1_onBlur IF len(Form1.TextBox1.value)=0 then alert ("请输入数值!") exit sub end if
IF IsNumeric(Form1.TextBox1.value)=false then alert ("必须为数值!") Form1.TextBox1.focus () exit sub end if End Sub </script>
1.定义一个文本框
<td>
<ASP:TextBox id=TextBox1 runat=server />
</td>
2.加入正则表达式验证(假设你要求输入的是全数字)
<td>
<asp:RegularExpressionValidator id="RegularExpressionValidator1" runat="server"
ControlToValidate="TextBox1"
ValidationExpression="^[0-9]*$"
Display="Static"
Font-Name="verdana" Font-Size="10pt">
只能输入数字
</asp:RegularExpressionValidator>
</td>
定义一个文本框:<ASP:TextBox id=TextBox1 runat=server />
只能输入数字的脚本如下:
<script language="vbscript">
Sub TextBox1_onBlur
IF len(Form1.TextBox1.value)=0 then
alert ("请输入数值!")
exit sub
end if
IF IsNumeric(Form1.TextBox1.value)=false then
alert ("必须为数值!")
Form1.TextBox1.focus ()
exit sub
end if
End Sub
</script>