Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8698855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:48:53+00:00 2026-06-13T01:48:53+00:00

I am using data annotations with MVC2 to validate a date of birth. The

  • 0

I am using data annotations with MVC2 to validate a date of birth. The date of birth has 3 different fields. (Month, Day and Year) (they have to be three individual fields)

Right now I have individual data annotations for each field. How can I make it so that all three fields are validated and show one error message in my view. The setup I have right now creates an error message for each field.

If any one of those fields throws an error, I want to show a generic error message like "Date of Birth invalid".

Month Field:

        [Required]
        [DisplayName("Month")]
        public IEnumerable<string> Months 
        { 
            get 
            {
                if (_Months == null)
                {
                    List<string> months = new List<string>();
                    months.Add("-- Select Month --");
                    months.AddRange(DateTimeFormatInfo.CurrentInfo.MonthNames.Select(Month => Month).ToList());
                    months.RemoveAt(months.Count - 1);
                    _Months = months;
                }
                return _Months;
            }
            set { _Months = value; }
        }

        private IEnumerable<string> _Months;

        public string SelectedMonth {get; set;}

Day Field:

    [Required]
    [DisplayName("Day")]
    [Range(1,31, ErrorMessage = "Not a valid day")]
    public int? Day { get; set; }

Year Field:

    [Required]
    [DisplayName("Year")]
    [Range(1900,9999, ErrorMessage = "Not a valid year")]
    [ValidateBirthYear]
    public int? Year { get; set; } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T01:48:54+00:00Added an answer on June 13, 2026 at 1:48 am

    You might want to check out this question. They are looking to validate a datetime that is separated into three fields as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using linq to SQL and MVC2 with data annotations and I'm having some
I have some problems with validation using Data Annotations in ASP.NET MVC 2. For
I'm using MVC2 with data annotations for validation on my page. I require a
I'm using ASP.NET MVC 3 code-first and I have added validation data annotations to
I like the idea of using the data annotations to specify validation of fields
I am using Validator.TryValidateObject() to validate an object that uses data annotations. When the
Traditionally, I have built MVC applications using view models with Data Annotations attributes, and
In my simple class I'm using data annotations to map properties to columns as
I am using the Data Annotation Validator, outlined here: http://www.asp.net/learn/mvc/tutorial-39-cs.aspx The Data Annotations Model
I'm using Razor and Data Annotations in a .NET 4.5 MVC app. This is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.