javascript - Custom validator dynamic message -
i want custom validator dynamic messages. custom validator required field , regular expression. don't want use required field validator , regular expression validator creates more problems me. here javascript code
<script type="text/javascript"> function checkmytext(sender, args) { var compare = regexp("^.{1,10}$"); args.isvalid = compare.test(args.value) return; } </script>
here custom validator , text field code
<asp:textbox id="summary" runat="server" width="627px" cssclass="texrbox"></asp:textbox> <asp:customvalidator id="customvalidator2" runat="server" clientvalidationfunction="checkmytext" controltovalidate="summary" errormessage="" text="*" validateemptytext="true"></asp:customvalidator>
it working fine want show message when regular expression error fired only 10 characters allowed , required field want show required field. how it. want show bith messages in validation summary.
a validator renders <span>
element in html. can use change error message.
document.getelementbyid('<%= customvalidator2.clientid %>').innerhtml = "my custom error msg";
or change errormessage:
<%= customvalidator2.clientid %>.errormessage = "error summary";
Comments
Post a Comment