Created
February 14, 2013 19:41
-
-
Save emiaj/4955707 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
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