Skip to content

Instantly share code, notes, and snippets.

@emiaj
Created February 14, 2013 19:41
Show Gist options
  • Save emiaj/4955707 to your computer and use it in GitHub Desktop.
Save emiaj/4955707 to your computer and use it in GitHub Desktop.
public class RegexFieldRule : IRemoteFieldValidationRule
{
private readonly Regex _regex;
public RegexFieldRule(Regex regex)
{
_regex = regex;
}
public void Validate(Accessor accessor, ValidationContext context)
{
var value = (string) accessor.GetValue(context.Target);
if(value.IsEmpty())
{
return;
}
if(!_regex.IsMatch(value))
{
context.Notification.RegisterMessage(accessor, Token);
}
}
public StringToken Token { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment