Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

ValidatorExtensions.cs

using FluentValidation;
using FluentValidation.Validators;
using Nop.Core;
using Nop.Core.Domain.Customers;
using Nop.Services.Localization;

namespace Nop.Web.Framework.Validators;

/// 
/// Validator extensions
/// 
public static class ValidatorExtensions
{
    /// 
    /// Set credit card validator
    /// 
    /// Type of model being validated
    /// Rule builder
    /// Result
    public static IRuleBuilderOptions IsCreditCard(this IRuleBuilder ruleBuilder)
    {
        return ruleBuilder.SetValidator(new CreditCardPropertyValidator());
    }

    /// 
    /// Set decimal validator
    /// 
    /// Type of model being validated
    /// Rule builder
    /// Maximum value
    /// Result
    public static IRuleBuilderOptions IsDecimal(this IRuleBuilder ruleBuilder, decimal maxValue)
    {
        return ruleBuilder.SetValidator(new DecimalPropertyValidator(maxValue));
    }

    /// 
    /// Set username validator
    /// 
    /// Type of model being validated
    /// Rule builder
    /// Customer settings
    /// Result
    public static IRuleBuilderOptions IsUsername(this IRuleBuilder ruleBuilder,
        CustomerSettings customerSettings)
    {
        return ruleBuilder.SetValidator(new UsernamePropertyValidator(customerSettings));
    }

    /// 
    /// Set phone number validator
    /// 
    /// Type of model being validated
    /// Rule builder
    /// Customer settings
    /// Result
    public static IRuleBuilderOptions IsPhoneNumber(this IRuleBuilder ruleBuilder,
        CustomerSettings customerSettings)
    {
        return ruleBuilder.SetValidator(new PhoneNumberPropertyValidator(customerSettings));
    }

    /// 
    /// Implement password validator
    /// 
    /// Type of model being validated
    /// Rule builder
    /// Localization service
    /// Customer settings
    /// Result
    public static IRuleBuilder IsPassword(this IRuleBuilder ruleBuilder,
        ILocalizationService localizationService, CustomerSettings customerSettings)
    {
        return ruleBuilder.SetValidator(new PasswordPropertyValidator(localizationService, customerSettings));
    }

    /// 
    /// Set email address validator
    /// 
    /// Type of model being validated
    /// The rule builder on which the validator should be defined
    /// 
    public static IRuleBuilderOptions IsEmailAddress(this IRuleBuilder ruleBuilder)
    {
        return ruleBuilder.SetValidator(new EmailPropertyValidator());
    }
}