asp中我是这样写的 Function chknum(str) if IsNumeric(str)=false then response.write "数据错误,传入参数必须是数字" response.End else chknum=int(str) end if End Function
using System;namespace CSDN { class App { static bool CheckCharIsNumber(char c, out int i)//-99999999作为失败标记 { i = -99999999; bool b = char.IsNumber(c); if (b) { i = Convert.ToInt32(c); } return b; } static void Main(string[] args) { } } }
Function chknum(str)
if IsNumeric(str)=false then
response.write "数据错误,传入参数必须是数字"
response.End
else
chknum=int(str)
end if
End Function
using System;namespace CSDN
{
class App
{
static bool CheckCharIsNumber(char c, out int i)//-99999999作为失败标记
{
i = -99999999;
bool b = char.IsNumber(c);
if (b)
{
i = Convert.ToInt32(c);
}
return b;
}
static void Main(string[] args)
{ }
}
}
{
if (txt == "")
{
return true;
}
else
{
try
{
decimal val = Decimal.Parse(txt);
return true;
}
catch
{
return false;
}
}
}
public static bool fun(string txt)
{
string str="123456789";
for(int i=0;i<txt.length;i++)
{//通过循环判断下所输入的数据每一项是不是一个数字
if(str.Contains(txt[i]))
{ }
else
{
return false;//有一个不是则返回false;
}
}
return true;
}
{
double dNum;
if(double.TryParse(str, out dNum))//根据需要将double替换为其他数值类型
{
Console.WriteLine("输入正确!");
}
else
{
Console.WriteLine("输入的不是数字!");
dNum = null;
} return dNum;
}
private double IsNumber(string str)
{
double dNum;
if(double.TryParse(str, out dNum))//根据需要将double替换为其他数值类型
{
Console.WriteLine("输入正确!");
}
else
{
Console.WriteLine("输入的不是数字!");
dNum = null;
} return dNum;
}
借楼上的。
欢迎加入我的程序设计QQ群80532706哟
我的意思是
int userid=chknum(Request.QueryString["userid"])如果他传入的是数值则会正常运行 反之则在页面打印参数错误并停止程序运行!chknum这个函数不知道要怎么写```