using System; using System.Linq.Expressions; using System.Text.RegularExpressions; using FluentValidation; using FluentValidation.Validators; namespace NzbDrone.Api.Validation { public static class RuleBuilderExtensions { public static IRuleBuilderOptions ValidId(this IRuleBuilder ruleBuilder) { return ruleBuilder.SetValidator(new GreaterThanValidator(0)); } public static IRuleBuilderOptions IsZero(this IRuleBuilder ruleBuilder) { return ruleBuilder.SetValidator(new EqualValidator(0)); } public static IRuleBuilderOptions HaveHttpProtocol(this IRuleBuilder ruleBuilder) { return ruleBuilder.SetValidator(new RegularExpressionValidator("^http(s)?://", RegexOptions.IgnoreCase)).WithMessage("must start with http:// or https://"); } public static IRuleBuilderOptions IsValidPath(this IRuleBuilder ruleBuilder) { return ruleBuilder.SetValidator(new PathValidator()); } public static IRuleBuilderOptions NotBlank(this IRuleBuilder ruleBuilder) { return ruleBuilder.SetValidator(new NotNullValidator()).SetValidator(new NotEmptyValidator("")); } } }