最新下载
热门教程
- 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("不是数字"); }
}
相关文章
- oppok11玩游戏怎么样介绍 03-22
- 字母站是什么平台 03-22
- 如何删除emmo日记中的心情日记 03-22
- 万王之王3D铁卫技能加点推荐(铁卫技能加点详解及优化方案,助你成为无敌的王者!) 03-22
- 探秘第五人格佣兵天赋加点技巧(打造最强佣兵,助你成为游戏巅峰) 03-22
- 2026有用的老年人脑力训练游戏有什么 有趣的脑力训练游戏合集推荐 03-22