开发者

Multiattribute custom validtors

I was looking at t开发者_StackOverflow社区his article on custom validators in aps.net mvc 2 and I was wondering how I might go about creating a more complex validation which worked on multiple fields at once. Say something like

 if(fieldA > 7 and fieldB < 15)

The attribute method of creating validators doesn't seem like it would work for that.


I have started using Fleunt validation and is allows you to achieve quite complex validation with ease. While it takes some getting used to, I have found it very flexible. For example, here we make sure the length of a user password is between 7 and 15!

    public UserValidator() {
        RuleFor(user=> user.Password)
            .Length(7, 15)
            .WithMessage("Password to short/long");
    }
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜