开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜