印象笔记同类产品:CustomValidator实际应用篇
来源:百度文库 编辑:中财网 时间:2024/05/09 14:13:39
用CustomValidator验证文本框中输入的是否是数字 前台代码:
后台代码: //导入正则表达式空间 using System.Text.RegularExpressions; public bool IsNumeric(string sNumeric)
{
//用正则表达式来验证输入的字符串是否是数字
return (new Regex("^[\\+\\-]?[0-9]*\\.?[0-9]+$")).IsMatch(sNumeric);
}
protected void cvS_no_ServerValidate(object source, ServerValidateEventArgs args)
{
args.IsValid = IsNumeric(args.Value.Trim());
if (IsNumeric(args.Value.Trim())==true)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "myIsNumberKey1", "alert('Server:恭喜你,你输入的是数字!');", true);
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "myIsNumberKey2", "alert('Server:很遗憾,你输入的不是数字!');", true);
}
}