jqueryのform validate.jsでパスワードの重複表現をチェックしたいのですが、正規表現の書き方がわかりません。
若しくは、javascriptやjQueryで色々試しておりますが、うまく行きません。
下記コードで試すと「1111」という連続数字だけでなく、全部4桁の数字がNGになってしまいました。
正規表現でできなければ、javascriptやjQueryでも大丈夫です。
作品制作の段階なので、もちろんphp側でのサーバーサイドのバリデートはやるつもりでおります。
宜しくお願い致します。
html
1<!doctype html> 2<html> 3 <head> 4 <meta charset="utf-8"> 5 <title>パスワードの表示</title> 6 <script type="text/javascript" src="password.js"></script> 7 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js" type="text/javascript"></script> 8 <script type="text/javascript" src="jquery.validate.min.js"></script> 9 <script> 10 $(document).ready(function(){ 11 $("#form1").validate({ 12 rules: { 13 name : { 14 required: true, 15 minlength: 4, 16 maxlength: 20 17 }, 18 password :{ 19 required:true, 20 minlength:4, 21 maxlength: 4, 22 digits:true, 23 CustomValidateUserID:true 24 } 25 }, 26 messages: { 27 name: { 28 required: "名前を入力してください", 29 minlength: "4文字以上で入力してください", 30 maxlength: "10文字以内で入力してください", 31 }, 32 password :{ 33 required:"パスワードは必須です。", 34 minlength:"4文字入力してください。", 35 maxlength:"4文字入力してください。", 36 digits:"数字のみで入力してください。" 37 } 38 }, 39 40 41 errorPlacement: function(error,element){ 42 43 error.insertAfter($('#'+ element.attr('name') + '_err')); 44 } 45 }); 46 jQuery.validator.addMethod("CustomValidateUserID", 47 function(val,elem){ 48 reg = new RegExp("^(.)\1\1\1\$"); 49 return this.optional(elem) || reg.test(val); 50 }, 51 "連続して同じ数字を入れないでください!" 52 ); 53 }); 54 </script> 55 </head> 56 <body> 57 <form action="comfirm.php" onsubmit="return passwordCheck();"method="post" id="form1"> 58 名前:<br> 59 <label id="name_err"></label> 60 <input type="text" name="name" value=""><br> 61 パスワード:<br><label id="password_err"></label> 62 <input type="password" name="password" value="" id="password1" class="require"><br> 63 パスワードを表示<input type="checkbox" onclick="checkPassword(this)"/> 64 <p><input type="submit" name="submit" value="確認画面へ"></p> 65 </form> 66 </body> 67</html>
回答2件
あなたの回答
tips
プレビュー