string str="";
str = this.TextBox1.Text;
if (str == null || str.Length == 0)
{
Response.Write("window.alert('输入数字!')"); return;
}
foreach (char c in str)
{
if (!Char.IsNumber(c))
{
Response.Write("window.alert('输入数字!')"); return;
}
else
{
Response.Write("window.alert('yes!')");
}
}
如果你是在VS2005里的话验证控件用这个RegularExpressionValidator
设置属性ValidationExpression ^[0-9]*$