javascript - jQuery adding custom password rule not working -
i new jquery , using jquery form validator validate form..
the problem , have validate password must contain at-least 1 digit..
i searched on google , found example in here link forum.jquery
here snippet of html code
<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 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>
everything works fine until add line above code rules
pwd:{ required:true, minlength:5, mypassword: true }
i included additional scripting file contains following method
jquery.validator.addmethod('mypassword', function(value, element) { return this.optional(element) || (value.match(/[a-za-z]/) && value.match(/[0-9]/)); }, 'password must contain @ least 1 numeric , 1 alphabetic character.');
after trying execute above code, got following error message in browser console follows:
uncaught typeerror: cannot call method 'call' of undefined in js/jqueryvalidation.js
why additional method not working?
any or suggestions appreciated.
please check example in fiddler link : http://jsfiddle.net/naaew/
jquery.validator.addmethod('mypassword', function(value, element) { return this.optional(element) || (value.match(/[a-za-z]/) && value.match(/[0-9]/)); });
and message :
pwd:{ required:"please enter password", minlength:"please enter minimum characters", mypassword: 'password must contain @ least 1 numeric , 1 alphabetic character.'
hope expecting.
Comments
Post a Comment