how to check given date exist in month or not?

I have a combo Box In which I made a collection of dates from 1 to 31 and also I have a checklist box in which I made a collection of month from Jan to Dec.
Now I have to put validation on date that if user select 31 and select month Jan, Feb, Mar then a message popup and inform them 31 does not exist in February

enter image description here

Jon Skeet
people
quotationmark

You want the DateTime.DaysInMonth method:

public bool IsDateValid(int year, int month, int day) {
    return day <= DateTime.DaysInMonth(year, month);
}

I'm assuming that the year and month values will always be sensible, and that day will always be greater than or equal to 1. You could easily add argument validation. I'm also assuming that you already have the month as a number, rather than just a name. (Differentiate between the display format of a value and the underlying value.)

Note that you'll need a year picker, otherwise you won't know whether February 29th is valid or not.

(And as Mitch says, it would be better to design a UI where invalid choices simply don't appear, ideally.)

people

See more on this question at Stackoverflow