mirror of
https://github.com/lidarr/Lidarr
synced 2024-12-27 10:07:10 +00:00
34 lines
No EOL
1.3 KiB
C#
34 lines
No EOL
1.3 KiB
C#
using System.Text.RegularExpressions;
|
|
using FluentValidation;
|
|
using FluentValidation.Validators;
|
|
|
|
namespace NzbDrone.Api.Validation
|
|
{
|
|
public static class RuleBuilderExtensions
|
|
{
|
|
public static IRuleBuilderOptions<T, int> ValidId<T>(this IRuleBuilder<T, int> ruleBuilder)
|
|
{
|
|
return ruleBuilder.SetValidator(new GreaterThanValidator(0));
|
|
}
|
|
|
|
public static IRuleBuilderOptions<T, int> IsZero<T>(this IRuleBuilder<T, int> ruleBuilder)
|
|
{
|
|
return ruleBuilder.SetValidator(new EqualValidator(0));
|
|
}
|
|
|
|
public static IRuleBuilderOptions<T, string> HaveHttpProtocol<T>(this IRuleBuilder<T, string> ruleBuilder)
|
|
{
|
|
return ruleBuilder.SetValidator(new RegularExpressionValidator("^http(s)?://", RegexOptions.IgnoreCase)).WithMessage("must start with http:// or https://");
|
|
}
|
|
|
|
public static IRuleBuilderOptions<T, string> IsValidPath<T>(this IRuleBuilder<T, string> ruleBuilder)
|
|
{
|
|
return ruleBuilder.SetValidator(new PathValidator());
|
|
}
|
|
|
|
public static IRuleBuilderOptions<T, string> NotBlank<T>(this IRuleBuilder<T, string> ruleBuilder)
|
|
{
|
|
return ruleBuilder.SetValidator(new NotNullValidator()).SetValidator(new NotEmptyValidator(""));
|
|
}
|
|
}
|
|
} |