You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Lidarr/src/NzbDrone.Core/Validation/UrlValidator.cs

32 lines
894 B

using FluentValidation;
using FluentValidation.Validators;
using NzbDrone.Common.Extensions;
namespace NzbDrone.Core.Validation
{
public static class UrlValidation
{
public static IRuleBuilderOptions<T, string> IsValidUrl<T>(this IRuleBuilder<T, string> ruleBuilder)
{
return ruleBuilder.SetValidator(new UrlValidator());
}
}
public class UrlValidator : PropertyValidator
{
protected override string GetDefaultMessageTemplate() => "Invalid Url: '{url}'";
protected override bool IsValid(PropertyValidatorContext context)
{
if (context.PropertyValue == null)
{
return false;
}
context.MessageFormatter.AppendArgument("url", context.PropertyValue.ToString());
return context.PropertyValue.ToString().IsValidUrl();
}
}
}