最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
判断用户输入为数字函数
时间:2011-02-13 编辑:简简单单 来源:一聚教程网
判断用户输入为数字函数
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("不是数字"); }
}
-
下一个: 正则字符串中含有超连接代码
相关文章
- C#复制数组的两种方式及效率比较解读 10-24
- ASP.NET Identity用法解析 10-24
- ASP.NET MVC使用Identity增删改查用户介绍 10-24
- C语言中atoi函数模拟实现介绍 10-18
- .Net反向代理组件Yarp用法介绍 10-10
- .NET使用YARP通过编码方式配置域名转发实现反向代理教程 10-10