Link to home
Start Free TrialLog in
Avatar of pigmentarts
pigmentartsFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Validation for age using asp.net, How??????????????????

I need some validation for my form, i have a text box where you enter your age, I need some sort some validation which will not allow someone under 18 year of age!

Can someone help, thanks.

PS i am using asp.net vbscript.
Avatar of ihenry
ihenry

This RangeValidator control validates when TextBox1 has integer value range from 18 to 100

<asp:RangeValidator id="RangeValidator1" runat="server" ErrorMessage="RangeValidator" Display="Dynamic"
      ControlToValidate="TextBox1" Type="Integer" MinimumValue="18" MaximumValue="100"></asp:RangeValidator>
Avatar of pigmentarts

ASKER

sorry i ment to say there enter there birth date no there age, so i need something that checks this date to see if they are over 18 years old.
well u can use a custom validator or u can use a javascript function to do the validation
i need a  custom validator, any example in vb for me?
did it this way

<asp:CustomValidator ClientValidationFunction='"dob" > DateTime.Now.AddYears(-18)' ControlToValidate="dob" Display="Dynamic" EnableClientScript="true" ErrorMessage="you must be over 18" ID="dobValidator" runat="server" />


seems to work fine.
SOLUTION
Avatar of shovavnik
shovavnik

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i can not get the script to work i can not convert it.

Exception Details: System.Web.HttpException: The value '01/01/0001 00:00:00' of the ValueToCompare property of 'AgeCompareValidator' cannot be converted to type 'Date'.
shovavnik
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial