第1个回答 2006-10-03
//导入命名空间
using System.Text.RegularExpressions
//使用正则表达式进行判断,第一种方法
Regex re;
MatchCollection mc;
mc=re.Matches(txtTest.Text,"[^0-9]");
if(mc.count>0)
{
txtTest.Text="";
Response.Write("<script language=javascirpt type='text/javascript'>");
Response.Write("window.alert('输入非数字字符,请重新输入!')");
Response.Write("</script>");
}
else
{
//做进一步的处理
}
//第二种方法,不需要导入命名空间
//加个表达式的验证控件,正则表达式里输入"\d+" 就可以了