c# - Range validator not working -
i trying put asp.net required field validator , range validator required field validator works not range. why ?
<asp:textbox id="txtcnic" runat="server" cssclass="textfield_width"></asp:textbox> <asp:requiredfieldvalidator id="requiredfieldvalidator2" runat="server" controltovalidate="txtcnic" errormessage="requiredfieldvalidator" forecolor="#ff3300" setfocusonerror="true" validationgroup="complaints">cnic required</asp:requiredfieldvalidator> <asp:rangevalidator controltovalidate="txtcnic" minimumvalue="14" maximumvalue="16" type="string" validationgroup="complaints" enableclientscript="false" text="cnic can not longer 15 characters" runat="server" /> <asp:button id="btnsave" cssclass="btn btn-success" runat="server" text="save" validationgroup="complaints" clientidmode="static" onclick="btnsave_click" />
asp rangevalidator
meant validate input within given range, whereas in case seems want validate input length. this, can this:
in page, replace rangevalidator
customvalidator
:
<asp:customvalidator runat="server" id="txtcnicvalidator" controltovalidate="txtcnic" clientvalidationfunction="validatecnic" errormessage="cnic must 15 characters long!" />
and add corresponding validation function in javascript:
<script type="text/javascript"> function validatecnic(sender, args) { args.isvalid = (args.value.length == 15); } </script>
Comments
Post a Comment