"^\\d+$" //非负整数(正整数 + 0)
"^[0-9]*[1-9][0-9]*$" //正整数
"^((-\\d+)|(0+))$" //非正整数(负整数 + 0)
"^-[0-9]*[1-9][0-9]*$" //负整数
"^-?\\d+$" //整数
"^\\d+(" //非负浮点数(正浮点数 + 0)
"^(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*))$" //正浮点数
"^((-\\d+(" //非正浮点数(负浮点数 + 0)
"^(-(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*)))$" //负浮点数
"^(-?\\d+)(" //浮点数
<script language="javascript">
function chkads()
{
if (lf_addstu.sname.value=="")
{
alert("姓名不能为空.");
lf_addstu.sname.select();
return false;
}
if (lf_addstu.tpl.value=="")
{
alert("联系电话不能为空.");
lf_addstu.tpl.select();
return false;
}
if(!IsNum(lf_addstu.tpl.value)){
alert("请输入数字!")
lf_addstu.tpl.focus();
return false;
}
}
function IsNum(num){
var reNum=/^\d*$/;
return(reNum.test(num));
}
</script>
<form style="padding:0; margin:0" action="" method="post" onSubmit="return chkads()" id="lf_addstu" name="lf_addstu">
姓名<br />
<input name="sname" type="text" /><br />
详细地址<br />
<input name="adress" type="text" /><br />
邮编<br />
<input name="codes" type="text" /><br />
联系电话<br />
<input name="tpl" type="text" /><br />
E-mail<br />
<input name="email" type="text" />
<input type="image" src="img/wanhui06.jpg" alt="提交" />
</form>
protected void Button2_Click(object sender, EventArgs e)
{
//判断正整数
int j=0;
for (int i = 0; i < TextBox1.Text.Length; i++)
{
if (char.IsNumber(TextBox1.Text, i))//这个方法用来判断整数还可以,判断负数和小数就失效了
j++;
}
if (j == TextBox1.Text.Length)
{
Response.Write("ok");
}
else
{ Response.Write ("no");}
}
public bool IsNumber( object obj)
{
bool result = true;
try
{
string str = obj.ToString();
double d ;
d = double.Parse(str);
}
catch
{ //parse 函数进行转换,不成功则抛出异常
result = false;
}
return result;
}
protected void Button3_Click1(object sender, EventArgs e)
{
//判断数
if (IsNumber(TextBox1.Text))
{
Response.Write("是数字");
}
else
{ Response.Write("不是数字"); }
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有