Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
- public sealed class ValidateDODDOB : ValidationAttribute
- {
- // Error Message
- private const string DefaultErrorMessage = "Please type the date in the format specified.";
- // Gets or sets the Regular expression.
- private Regex Regex { get; set; }
- // The pattern used for Date of Birth and Date of Death validation.
- public string Pattern { get { return @"(\d+\s?)?(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)?\s(\d+\s)?(BCE)?"; } }
- // Initializes a new instance of the VerifyDODDOB class.
- public ValidateDODDOB() : base(DefaultErrorMessage)
- {
- this.Regex = new Regex(this.Pattern);
- }
- // Determines whether the specified value of the object is valid.
- // true if the specified value is valid; otherwise, false.
- public override bool IsValid(object value)
- {
- // convert the value to a string
- var stringValue = Convert.ToString(value);
- var m = Regex.Match(stringValue);
- return m.Success;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement