Created
October 11, 2012 01:44
-
-
Save detroitpro/3869642 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] | |
| public class CvvAttribute : DataTypeAttribute | |
| { | |
| public CvvAttribute() | |
| : base("cvv") | |
| { | |
| } | |
| public override string FormatErrorMessage(string name) | |
| { | |
| if (ErrorMessage == null && ErrorMessageResourceName == null) | |
| { | |
| ErrorMessage = "CVV is not valid"; | |
| } | |
| return base.FormatErrorMessage(name); | |
| } | |
| public override bool IsValid(object value) | |
| { | |
| if (value == null) | |
| { | |
| return true; | |
| } | |
| var regex = new Regex(@"^(?!000)\d{3,4}$", RegexOptions.Compiled | RegexOptions.IgnoreCase); | |
| var asString = value.ToString(); | |
| var match = regex.Match(asString).Length > 0; | |
| return match; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment