Skip to content

Instantly share code, notes, and snippets.

@trnktms
Created February 17, 2017 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trnktms/67ad17fbb2e786d7321e071dc0c7c400 to your computer and use it in GitHub Desktop.
Save trnktms/67ad17fbb2e786d7321e071dc0c7c400 to your computer and use it in GitHub Desktop.
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