Credit Card Expiry Date validation for Custom Validator
Function validateexpirydate(sender,args) { var txtvalue=args.value; var i=txtvalue.indexof('/'); var dt=new date(); var dtyear=dt.getfullyear(); var dtmonth=dt.getmonth(); var stryear=dtyear+''; var strsubstring=stryear.substring(2,4);//current year=07 var strsubstring1=stryear.substring(0,2);//current year prefix=20 if(i==2)//checking '/' character { var yearpart=txtvalue.substring(i+1,5);//checking separatley year part with textbox value var monthpart=txtvalue.substring(0,2)-1;//checking separatley month part with textbox value var currentyear=strsubstring1+yearpart;//current year prefix + user entered year if(currentyear==dtyear) { if(monthpart>=0 && monthpart<=11) { if(monthpart>dtmonth) { args.isvalid=true; return true; } else { args.isvalid=false; return false; } } else { args.isvalid=false; return false; } } else if(currentyear>dtyear) { if(monthpart>=0 && monthpart<=11) { args.isvalid=true; return true; } else { args.isvalid=false; return false; } } else { args.isvalid=false; return false; } } else { args.isvalid=false; return false; } } html code -------------------- <asp:textbox id="txtexpirydate" runat="server" maxlength="5" width="40" cssclass="ibox01" /><asp:requiredfieldvalidator id="requiredfieldvalidator3" runat="server" display="dynamic" controltovalidate="txtexpirydate" errormessage="please enter exipry date">*</asp:requiredfieldvalidator><asp:regularexpressionvalidator id="regularexpressionvalidator3" runat="server" display="dynamic" controltovalidate="txtexpirydate" errormessage=" allows only date" validationexpression="^[0-9\/]*$">*</asp:regularexpressionvalidator> <asp:customvalidator id="customvalidator2" runat="server" errormessage="your expiry date is invalid" controltovalidate="txtexpirydate" display="dynamic" clientvalidationfunction="validateexpirydate">*</asp:customvalidator>
Re: Credit Card Expiry Date validation for Custom Validator
can you please edit your post to displaying clearly? I am not able to get clearly.
There is an edit option in your post.
-----------------------
suresh