繁体   English   中英

使用正则表达式和jQuery插件进行验证

[英]Validation with regular expression and jQuery Plugin

我喜欢使用JavaScript进行客户端验证。 为此,我在这里使用jQuery插件Validate()观看: http : //docs.jquery.com/Plugins/Validation/Methods

通过单击提交按钮,我想将iput字段中的ID与正则表达式进行比较。 我该如何解决?

现在,我这样做是这样的:

<form id="checkoutFormBean" action="/view/checkout?execution=e3s1" method="POST">
    <li>
    <input id="id" name="id" class="fieldError required number" tabindex="12" value="" maxlength="2048" type="text">
    </li> 


    <script type="text/javascript">
            $(document).ready(function(){
                $("#checkoutFormBean").validate({
                    id: "required",
                    id: {
                        equalTo: "/^2099[0-9]{9}$/"
                    }
                });
            });

        </script>

但是它不起作用

提交后,您只需要使用规则进行验证。请查看以下网址。您将在此处了解如何指定规则。

例如:

$("#checkoutFormBean").validate({
   rules: {
     name: {
       required: true,
       equalTo: "/^2099[0-9]{9}$/"
     }
   }
});

希望这对您有所帮助:-)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM