最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
判断用户输入为数字函数
时间:2022-06-25 03:14:43 编辑:袖梨 来源:一聚教程网
判断用户输入为数字函数
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("不是数字"); }
}
相关文章
- AI漫剧伪装直男1‑24集无雾版夸克网盘资源免费分享 10-26
- 韩漫在线免费漫画入口-最新韩漫免费阅读入口 10-26
- 海角社区最新登录入口-2026海角官网在线登录直达地址 10-26
- mcjs网页版即点即玩-mcjs极速秒玩入口 10-23
- 超星学习通网页版登录-超星学习通官网入口 10-23
- poki免费游戏大全-poki免费游戏在线畅玩入口 10-23