Using DataTypeAttribute to validate a date

Posted by Andy Evans on Stack Overflow See other posts from Stack Overflow or by Andy Evans
Published on 2010-05-22T15:00:03Z Indexed on 2010/05/22 15:20 UTC
Read the original article Hit count: 232

Filed under:

I'm having some difficulty understanding how to validate a date (DOB) using MVC2. What I want to do is 1. Is the date entered a valid date and, 2. Is the date at lease 13 years in the past. For example, to validate an email I use the following code:

[Required(ErrorMessage = "Email address is required.")]  
[StringLength(320, ErrorMessage = "Email must be less than 320 characters.")]  
[Email(ErrorMessage = "This email address is invalid.")]  
public string email { get; set; }  

To validate the email I use:

public class EmailAttribute : RegularExpressionAttribute
{        
    public EmailAttribute()
        : base("insert long regex expression here") { }
}

Any assistance would be greatly appreciated, thanks!

© Stack Overflow or respective owner

Related posts about asp.net-mvc-2