Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery添加自定义密码规则不起作用_Javascript_Jquery_Validation_Jqueryform - Fatal编程技术网

Javascript jQuery添加自定义密码规则不起作用

Javascript jQuery添加自定义密码规则不起作用,javascript,jquery,validation,jqueryform,Javascript,Jquery,Validation,Jqueryform,我是jQuery新手,我正在使用jQuery表单验证程序验证我的表单 问题是,我必须验证密码,因为它必须至少包含一个数字 我在谷歌上搜索,在这里找到了一个例子 下面是我的HTML代码片段 <form name="f2" id="f2" method="post" action="hello"> <table> <tr> <th> Password

我是jQuery新手,我正在使用jQuery表单验证程序验证我的表单

问题是,我必须验证密码,因为它必须至少包含一个数字

我在谷歌上搜索,在这里找到了一个例子

下面是我的HTML代码片段

  <form  name="f2" id="f2" method="post" action="hello">
     <table>
      <tr>
             <th>
                 Password
             </th>
              <td>
             <input type="password" name="pwd" id="pwd"  placeholder="Enter Password" class="text_box">
              </td>
      </tr>
      <tr>
           <td>
              <button type="submit" class="submit-button">Register</button>
           </td>
      </tr>

     </table>
    </form>

    //jquery script for form validation

      <script>
        $(document).ready(function(){
            $("#f2").validate({
                debug: false,
                rules: { 

                 pwd:{
                        required:true,
                        minlength:5
                    }

                 },
                messages:
                    {
                      pwd:{
                        required:"Please enter password",
                        minlength:"Please enter minimum characters"
                    }
                 }
             });
        });
    </script>
我包括了包含以下方法的附加脚本文件

jQuery.validator.addMethod('mypassword', function(value, element) 
{
    return this.optional(element) || (value.match(/[a-zA-Z]/) && value.match(/[0-9]/));
},
'Password must contain at least one numeric and one alphabetic character.');
尝试执行上述代码后,我在浏览器控制台中收到以下错误消息,如下所示:

未捕获的TypeError:无法调用中未定义的方法“call” js/jqueryvalidation.js

为什么附加方法不起作用


任何帮助或建议都将不胜感激。

请查看fiddler链接中的示例:

和信息:

    pwd:{
                    required:"Please enter password",
                    minlength:"Please enter minimum characters",
      mypassword: 'Password must contain at least one numeric and one alphabetic character.'

希望这是您所期望的。

您是否为mypassword添加了消息?否。事实上,如果条件错误,附加方法将返回消息。请提供$f2jsfiddle@dholakiyaankit我不知道如何创作小提琴。。请稍等,我将提供我的代码片段HTMLTH,它工作了…一个小错误,但需要6个小时才能解决。我必须掌握jquery。我将从现在开始。谢谢
    jQuery.validator.addMethod('mypassword', function(value, element) 
    {
       return this.optional(element) || (value.match(/[a-zA-Z]/) && value.match(/[0-9]/));
    });
    pwd:{
                    required:"Please enter password",
                    minlength:"Please enter minimum characters",
      mypassword: 'Password must contain at least one numeric and one alphabetic character.'