如何使用jquery为控件禁用和启用RequiredFieldValidator

时间:2013-03-04 12:23:23

标签: jquery asp.net requiredfieldvalidator

在一个页面中我有两个单选按钮,其中一个选中我将通过使用名为'person'和'organization'的类在此页面中显示一些控件。此外,我想检查用户在输入文本控件中输入正确的数据。如何在客户端验证数据?  例如:

<input runat="server" id="txtnationalid" maxLength="10" name="txtnationalid" class='person ltr glow-onfocus customerCode required number' dir="ltr" />
<asp:RequiredFieldValidator Display="Dynamic" runat="server" ID="txtcodecv1" ErrorMessage="it can not be null" ControlToValidate="txtnationalid" ></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ValidationExpression="[0-9]{10}" Display="Dynamic" runat="server" id="txtcodev2" ErrorMessage="it's not in correct format" ControlToValidate="txtnationalid" ></asp:RegularExpressionValidator>
<input runat="server" id="txteconomiccode" maxLength="15" name="txteconomiccode" class='organization ltr glow-onfocus customerCode required number' dir="ltr" />
<asp:RequiredFieldValidator Display="Dynamic" runat="server" id="txtcodecv3" ErrorMessage="economiccode required" ControlToValidate="txteconomiccode"></asp:RequiredFieldValidator>                         

1 个答案:

答案 0 :(得分:0)

你可以使用jQuery                        

  <script>
  $(document).ready(function(){
    $("#commentForm").validate();
  });
  </script>

</head>
<body>


 <form class="cmxform" id="commentForm" method="get" action="">
   <input type="text" name="firstName" class="required"/>
 <input type="submit" value="submit"/>
 </form>
</body>
</html>

see here了解模式详情