adding ValidationExpression to customvalidator in asp.net
i have this ValidationExpression="(\d{1,}.{0,2} .{2,})|(.{2,} \d{1,}.{0,2})" used in regularexpression validator. I want to use the 开发者_C百科same one in a customvalidator. But customvalidator does not have option validationexpression. how can i add this in code or in tag. Please give me sample.
Use ASP.NET Regex Class.
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
if (!Regex.IsMatch(args.Value,@"^(\d{1,}.{0,2} .{2,})|(.{2,} \d{1,}.{0,2})$"))
{
args.IsValid = false;
}
else
{
args.IsValid = true;
}
}
Note: You will need System.Text.RegularExpressions namespace reference.
精彩评论