473,406 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to validate a date of birth (age) if minimum is 18 in C#

2
I'm new in C# and my code is as follows and I need help cause I'm getting an error that says:

The name 'date' does not exist in the current context


Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11.  
  12.  
  13. public partial class ValidationIdentity : System.Web.UI.Page
  14. {
  15.  
  16.  
  17.     protected void Page_Load(object sender, EventArgs e)
  18.     {
  19.  
  20.     }
  21.     protected void btnValidate_Click(object sender, EventArgs e)
  22.     {
  23.  
  24.         DateTime d = DateTime.Parse(date);
  25.  
  26.         if (d <= DateTime.Now.AddYears(-18))
  27.         {
  28.             Response.Write("Citizen");
  29.         }
  30.         else
  31.         {
  32.             Response.Write("<script>window.alert('Invalid Identity Number')</script>");
  33.         }
  34.  
  35.     }
  36.  
  37.     }
Feb 15 '11 #1
1 2569
GaryTexmo
1,501 Expert 1GB
I'm not really well versed in using C# on a webpage, but the error is pretty straight forward here. You're trying to access an object, date, that doesn't exist in the current method's scope.

If you want to get the user's age, you need to ask for it somehow. Your code that you posted doesn't show that.
Feb 15 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Frank Rocco | last post by:
Hello, What is the best way to validate a textbox to see if it contains a valid date or a valid time or both? Thanks Frank
2
by: Bogdan Zamfir | last post by:
Hi, I want to use RegularExpressionValidator to validate a date I want to let user to enter date in the following format one or two digits for day one or two digits for month two or four...
2
by: Grey | last post by:
I want to know that how to valiate date input from ASP.NET? can i use custom validator? if so, how to.. Million Thanks.
2
by: Fernando Lopes | last post by:
Hi. How can i validate a date textbox using validator, but the validator need to validate all data types, like: USA: 11/19/2004 BRAZIL: 19/11/2004 GERMANY: 19.11.2004 So, in the validator...
6
by: NH | last post by:
I want to allow users to enter dates in a text box in either the US "MM dd yy" format or the UK "dd MM yy" format. But how can I validate these dates? All the date functions e.g. ISdate,...
4
stormrider
by: stormrider | last post by:
Hi all, I'm trying to implement a Perl structure. My small program will do the followings; Take the birth date of the user as input. (Month's will be input as strings.) Take the current time...
2
by: Dinesh | last post by:
Hi experts, I am working on SQL server 2005 reporting services and i am getting a problem in writting a query. Situation is given below. There is one table in database Named Child Now i...
5
by: shapper | last post by:
Hello, What is the Regex expression to validate a date time format as follows: dd-mm-yyyy hh:mm:ss An example: 20-10-2008 10:32:45
1
vavc1980
by: vavc1980 | last post by:
Hello, I have a couple of textboxes where I enter a date range (From - To), I need to validate that the Date From is greater (future) or at least equal to the Date From, or else give an error. ...
12
by: lolodede | last post by:
i like to validate date of birth as format dd/mm/yyy i tried everything but is not working thank you
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.