public class MatchRegexCriterion()

in src/Azure.Deployments.Extensibility.Core/V2/Validation/Criteria/MatchRegexCriterion.cs [10:25]


    public class MatchRegexCriterion<TModel>(Regex regex) : IPropertyRuleCriterion<TModel, string?>
    {
        public string ErrorCode { get; set; } = "RegularExpressionMismatch";

        public string ErrorMessage { get; set; } = $"Value does not match the regular expression /{regex}/.";

        public IEnumerable<ErrorDetail> Evaluate(TModel model, string? propertyValue, JsonPointer propertyPointer)
        {
            ArgumentNullException.ThrowIfNull(propertyValue, nameof(propertyValue));

            if (!regex.IsMatch(propertyValue))
            {
                yield return new(this.ErrorCode, this.ErrorMessage, propertyPointer);
            }
        }
    }