Created
February 17, 2017 09:32
-
-
Save trnktms/67ad17fbb2e786d7321e071dc0c7c400 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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