<input id="txtDOB" type="text" maxlength="10" style="WIDTH: 100px" name="txtDOB" runat="server"> <br> <span style="FONT-SIZE: 7pt;FONT-FAMILY: arial">use mm/dd/yyyy as format<br> <asp:RequiredFieldValidator runat="server" Display="Dynamic" ControlToValidate="txtDOB" ErrorMessage="DOB is required.<br>" ID="Requiredfieldvalidator2"></asp:RequiredFieldValidator> <asp:RegularExpressionValidator runat="server" Display="Dynamic" ControlToValidate="txtDOB" ErrorMessage="DOB is required as mm/dd/yyyy.<br>" ID="RegEDOB" ValidationExpression="\d{2}\/\d{2}\/\d{4}"/> <asp:CustomValidator ID="cvDOBDate" dateBox="txtDOB" ErrorMessage="Age is not in range (18 - 90).<br>" ClientValidationFunction="ValidateAge" EnableClientScript=True Display="Dynamic" runat=server/> </span>And then this function on thye js include file:
//////////////////////////////////////////////////////// function calcAgeYears( f ) { // Get entered values var now = new Date(); // Generate date from input var xD = new Date(f); // Check generated date is OK if ( isNaN(xD.getDate()) ) { return 'Entered text is not valid'; } // Get date components var aY = xD.getFullYear(); var aM = xD.getMonth(); var aD = xD.getDate(); // Calculate age aY = now.getFullYear() - aY; aM = now.getMonth() - aM; aD = now.getDate() - aD; if ( aD < 0) { aD = now.getDate( now.setDate(aD) ); aM--; } if ( aM < 0 ) { aM += 12; aY--; } // return aY + 'y ' + aM + 'm ' + aD + 'd'; return aY ; } ///////////////////////////////////////////////////////// function ValidateAge(source, arguments) { var comparisonToday= new Date(); var todaysDate= new Date(document.getElementById(source.dateBox).value); var intDays; if(calcAgeYears(todaysDate) < 18 || calcAgeYears(todaysDate)>90 ) { arguments.IsValid = false; } else { arguments.IsValid = true; } }I just have a long js file with most of my validators...