What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 495 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > C# > How to validate age 18 or not? ...
Shubham

How to validate age 18 or not?

 Code Snippet posted by: Shubham | Posted on: 8/1/2012 | Category: C# Codes | Views: 692 | Status: [Member] | Points: 40 | Alert Moderator   


set a textbox(txtDob)on page and set the calender on textbox click event and select the date from calender...



protected void btn_Click(object sender, EventArgs e)
{
DateTime dtStart = DateTime.Parse(txtDoB.Text);
TimeSpan sp = DateTime.Now - dtStart;
int year =18\\\\\\ pass the no of year of no you want to validate
int days = 365;
int total = year * days;

if (sp.Days < total)
{

txtDoB.Text = "Not Valid";
lblMess.Text = "You can not be under 18 years";
lblMess.CssClass = "Errr";
return;
}

Thanks&Regards:-
Shubham Choudhary
Software Engineer
www.facebook.com/shubham.kunar
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/23/2013 8:48:45 PM