Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using Sitecore.Data;
using Sitecore.Rules.Conditions;
using MyProject.Foundation.Validation.Rules.Contexts;
namespace MyProject.Foundation.Validation.Rules.Conditions
{
public class FieldMaxLengthCondition<T> : IntegerComparisonCondition<T> where T : FieldValidatorsRuleContext
{
public string FieldId { get; set; }
protected override bool Execute(T ruleContext)
{
if (ID.Parse(FieldId) != ruleContext.FieldId)
{
return false;
}
var length = string.IsNullOrWhiteSpace(ruleContext.FieldValue) ? 0 : ruleContext.FieldValue.Length;
return BaseCompare(length);
}
public virtual bool BaseCompare(int value)
{
return Compare(value);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment