Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
hi
i need coding for date of birth feeld (month,date,year) with perfect validations.
thanks in advance
Posted
Updated 6-May-12 19:12pm
Comments
Sandeep Mewara 7-May-12 2:46am    
Reason for my vote of 1
No effort.
sandeep nagabhairava 7-May-12 7:04am    
effort means?
Sandeep Mewara 7-May-12 7:29am    
Being new does not give you a license to ask for codes online. You should try to learn. There are books, online tutorials, etc to read. Why ask for code without trying to do it by yourself?

You can use regular expression for date validation.
This link may help you http://regexlib.com/Search.aspx?k=date[^]
 
Share this answer
 
Look at C# DateTime.Parse and DateTime.TryParse methods:
DateTime.Parse Method [^]
DateTime.TryParse Method[^]
Parsing Date and Time Strings[^]
 
Share this answer
 
private int month;
private int year;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ArrayList arrayYear = new ArrayList();

int i;

for (i = 1990; i <= 2012; i++)
{
arrayYear.Add(i);
}
ArrayList arrayMonth = new ArrayList();
for (i = 1; i <= 12; i++)
{
arrayMonth.Add(i);
}
ddlyear.DataSource = arrayYear;
ddlyear.DataBind();
ddlyear.Items.Insert(0, new ListItem("-YY-", "-YY-"));
ddldate.Items.Insert(0, new ListItem("-DD-", "-DD-"));
ddlmonth.DataSource = arrayMonth;
ddlmonth.DataBind();
ddlmonth.Items.Insert(0, new ListItem("-MM-", "-MM-"));
}
}
private bool CheckLeapYear(int year)
{
year = Int32.Parse(ddlyear.SelectedValue);
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))

return true;

else
return false;
}
protected void year_SelectedIndexChanged(object sender, EventArgs e)
{
year = Int32.Parse(ddlyear.SelectedValue);
BindDays(year, month);
}
protected void month_SelectedIndexChanged(object sender, EventArgs e)
{
month = Int32.Parse(ddlmonth.SelectedValue);
BindDays(year, month);
}
private void BindDays(int year, int month)
{
int i;
ArrayList aday = new ArrayList();

switch (month)
{

case 1: case 3: case 5: case 7: case 8: case 10: case 12:
for (i = 1; i <= 31; i++)
{

aday.Add(i);
}
break;
case 2:
if (CheckLeapYear(year))
{
for (i = 1; i <= 29; i++)
aday.Add(i);
}
else
{
for (i = 1; i <= 28; i++)

aday.Add(i);
}

break;
case 4: case 6: case 9: case 11:
for (i = 1; i <= 30; i++)

aday.Add(i);
break;
}

ddldate.DataSource = aday;
ddldate.DataBind();
ddldate.Items.Insert(0, new ListItem("-DD-", "-DD-"));
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900