2013-08-22 08:08:43 +00:00
using System.Text.RegularExpressions ;
using FluentValidation ;
2013-04-20 22:14:41 +00:00
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 ) ) ;
}
2013-08-22 08:08:43 +00:00
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://" ) ;
}
2013-04-20 22:14:41 +00:00
}
}