javascript - How to validate password with atleast one numeric, one Uppercase letter and 6-20 characters? -
i have added script form , working alpha numeric.the problem when click on wrong format on click function updated data in database submit button.how can block? need update data correct alert function.
function checkpassword(inputtxt) { var passw = /^(?=.*\d)(?=.*[a-z])(?=.*[a-z]).{6,20}$/; if (inputtxt.value.match(passw)) { alert('congratulations have changed password!..plz logout , signin again.'); return true; } else { alert('wrong format...!') return false; } }
<script src="check-password-2.js"></script> <?php if(isset($_post['submit']) ) { $password = $_post['newpassword']; $sql = mysql_query("update tbl_login set str_password='$password',status='1' str_username='$user'"); } ?> <body onload='document.form1.newpassword.focus()'> <form name="form1" action="" method="post" id="form1" onclick="checkpassword(document.form1.newpassword)"> <table width="388" align="center"></br> </<tr> <td align="right">enter username</td> <td align="center"> <input type="username" name="username" value="<?php echo ucwords($_session['username']); ?> " class="txtbox" disabled="disabled" /> </td> </tr> <h5>input password , submit [6 20 characters contain @ least 1 numeric digit, 1 uppercase , 1 lowercase letter]</h5> <tr> <td align="right">new password</td> <td align="center"> <input type="password" name="newpassword" class="txtbox" /> </td> </tr> <tr> <td align="center"> <div align="center"> <input type="submit" name="submit" value="submit" /> </div> </td> </tr> </table> </form> </body>
firstly need use onsubmit
attribute of form
, not onclick
. secondly, need use return
statement within attribute provide value returned function event handler prevent or allow form submission. need fix several errors in html. try this:
<body onload='document.form1.newpassword.focus()'> <form name="form1" action="" method="post" id="form1" onsubmit="return checkpassword(document.form1.newpassword)"> <table width="388" align="center"></br> <tr> <td align="right">enter username</td> <td align="center"> <input type="username" name="username" value="<?php echo ucwords($_session['username']); ?> " class="txtbox" disabled="disabled" /> </td> </tr> <tr> <td colspan="2"> <h5>input password , submit [6 20 characters contain @ least 1 numeric digit, 1 uppercase , 1 lowercase letter]</h5> </td> </tr> <tr> <td align="right">new password</td> <td align="center"> <input type="password" name="newpassword" class="txtbox" /> </td> </tr> <tr> <td align="center"> <div align="center"> <input type="submit" name="submit" value="submit" /> </div> </td> </tr> </table> </form> </body>
Comments
Post a Comment