当前位置: 移动技术网 > IT编程>开发语言>.net > ASp.net 文本框(TextBox)计算,判断输入的是否是数字

ASp.net 文本框(TextBox)计算,判断输入的是否是数字

2017年12月12日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下:protected void txtqty_textchanged(object sender, eventargs e) { checkform();
复制代码 代码如下:

protected void txtqty_textchanged(object sender, eventargs e)
{
checkform();
}
//检验文本信息是否合法,如果合法则开始计算
protected void checkform()
{
try
{
if (!isnumberic(txtqty.text) && txtqty.text != "")
{
checkbool = false;
response.write("<script>alert('数量只能为数字,请输入数字信息,谢谢合作!')</script>");
txtqty.text = "";
txtqty.focus();
}
else if (txtqty.text != "")
{
qty = int.parse(txtqty.text);
}
if (!isnumberic(txtvat.text) && txtvat.text != "")
{
response.write("<script>alert('税额只能是数字,请输入数字信息,谢谢合作!')</script>");
checkbool = false;
txtvat.text = "";
txtvat.focus();
}
else if (txtvat.text != "")
{
vat = double.parse(txtvat.text);
}
if (!isnumberic(txtunitprice.text) && txtunitprice.text != "")
{
response.write("<script>alert('价格只能是数字,请输入数字信息,谢谢合作!')</script>");
checkbool = false;
txtunitprice.text = "";
txtunitprice.focus();
}
else if (txtunitprice.text != "")
{
unitprice = double.parse(txtunitprice.text);
}
if (checkbool == true)
{
if (vat != 0 && exvatamount != 0)
{
amountvat = exvatamount / (1 - vat / 100);
txtamountvat.text = amountvat.tostring();
}
}
}
catch (exception ex)
{
console.writeline(ex.message);
}
}
/// <summary>
/// 名称:isnumberic
/// 功能:判断输入的是否是数字
/// 参数:string otext:源文本
/// 返回值: bool true:是 false:否
/// </summary>
public bool isnumberic(string otext)
{
try
{
//从字符串到双精度值的转换,字符串转换为double,如果成功则返回为真,否则返回为假。
double var1 = convert.todouble(otext);
return true;
}
catch
{
return false;
}
}
}

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网