实现jquery插件添加方法验证

时间:2010-03-15 17:31:59

标签: asp.net jquery

使用jquery插件/验证时遇到问题。

我想添加一个方法并按照文档进行操作,但我想我还是遗漏了一些东西。

首先我添加方法,但我认为实施它有问题。

请检查我的代码并给我建议。

   <script src="js/jquery-1.4.1.js" type="text/javascript"></script>

    <script src="js/jquery.validate.js" type="text/javascript"></script>


    <script type="text/javascript">



        $(document).ready(function() {

        jQuery.validator.addMethod("domain", function(value, element) {
            return this.optional(element) || /^http:\/\/yahoo.com/.test(value);
        }, "Please specify the correct domain for your documents");



            $("#aspForm").validate();
        });

   <asp:TextBox ID="TextBox1" runat="server" CssClass="domain" ></asp:TextBox>


</script>

1 个答案:

答案 0 :(得分:0)

我能够找到如何实现验证规则的正确代码: 这是代码:

<script src="js/jquery-1.4.1.js" type="text/javascript"></script>

    <script src="js/jquery.validate.js" type="text/javascript"></script>


    <script type="text/javascript">


   //Our validation script will go here.
        $(document).ready(function() {

           jQuery.validator.addMethod("domain", function(value, element) {
            return this.optional(element) || /^http:\/\/yahoo.com/.test(value);
        }, "Please specify the correct domain for your documents");





            //validation implementation will go here.
            $("#aspnetForm").validate({
                rules: {
                    "<%=TextBox1.UniqueID %>": {

                        domain: true
                    }
                }

            });
        })

</script>

相关问题