javascript - Prevent future date and today date using custom validator -


i'm developing project using entity framework in .net 4. there page sign has field of date of birth. want validate date of birth cant in future or today. if 5 years compared today.

here code.

date of birth: <asp:requiredfieldvalidator id="rfv_txtbx_dob" runat="server" controltovalidate="txtbx_dob" cssclass="validator" display="dynamic" errormessage="date of birth required" setfocusonerror="true" text="*" validationgroup="vg" /> <asp:customvalidator id="cv_txtbx_dob" runat="server"  controltovalidate="txtbx_dob" cssclass="validator" display="dynamic"      errormessage="date of birth cannot today or in future" setfocusonerror="true" text="*" validationgroup="vg" clientvalidationfunction="validatedate"/> <asp:textbox id="txtbx_dob" runat="server" cssclass="txtbx" width="200px" /> <ajaxtoolkit:calendarextender id="txtbx_dob_calendarextender" runat="server" enabled="true" format="dd-mm-yyyy" targetcontrolid="txtbx_dob" /> <script language="javascript" type="text/javascript">     function validate(sender, args) {         var currentdate = new date().getdate();              if (args.value < currentdate)                 args.isvalid = true;             else                 args.isvalid = false;         } </script> 

function check_date() { var chkdate = document.getelementbyid("id of text field here").value;  var edate = chkdate.split("/"); var spdate = new date(); var sdd = spdate.getdate(); var smm = spdate.getmonth(); var syyyy = spdate.getfullyear(); var today = new date(syyyy,smm,sdd).gettime(); var e_date = new date(edate[2],edate[1]-1,edate[0]).gettime(); if(e_date > today)  {     alert("date not valid");     return false;  } } 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -