why Password validation not woprking

why Password validation not woprking

Hi,

I am using below code..

My problem, when I enter the password and retype both less than 5 it works but when I enter 5 in the password and 4 in the retype it just proceed and gives successfully changed.

How to fix this please?


  1. $("#frmResetPassword").validate({
  2. invalidHandler: function(form, validator)
  3. {
  4. form.preventDefault();
  5. $('#txtPassword').valid();
  6. $('#txtRetypePassword').valid();
  7. $('#divTitle').css("background-color", "#FF0000");
  8. $('#msgHeader').text("Error!");
  9. $('#msgAlert').html("Please enter & retype your Password!<br><br>1. Must start with a capital letter.<br><br>2. Must be at least 6 digits.<br><br>3. Must have at least one number");
  10. $('#dialogAlert').popup();
  11. $("#dialogAlert").popup("open");
  12. return false;
  13. },
  14. rules:
  15. {
  16. txtPassword:
  17. {
  18. minlength : 5,
  19. required: true
  20. },
  21. txtRetypePassword:
  22. {
  23. required: true,
  24. minlength : 5,
  25. equalTo: "#txtPassword"
  26. }
  27. },
  28. submitHandler: function (form)
  29. {
  30. $("#btnResetPassword").parent().hide();
  31. $.mobile.loading('show', {theme:"c", text:"Please wait..", textonly: false, textVisible: true});

  32. $.ajax({
  33. method: 'POST',
  34. url: "change_password.php",
  35. // dataType: "json",
  36. data: $('#frmResetPassword').serialize()
  37. // data: $(form).serialize()
  38. }).done(function(data)
  39. {
  40. $.mobile.loading('hide');
  41. if (data == "true")
  42. {
  43. $('#divTitle').css("background-color", "");
  44. $('#msgHeader').text("Thank you");
  45. $('#msgAlert').html("Your Password was successfully Changed.<br><br>Please sign in using the new Password.");

  46. $('#dialogAlert').popup();
  47. $("#dialogAlert").popup("open");
  48. $("#dialogAlert").on("popupafterclose", function( event, ui )
  49. {
  50. $.mobile.loading('show', {theme:"c", text:"Please wait..", textonly: false, textVisible: true});
  51. window.location.href = "index.php?signout=true";
  52. });
  53. }
  54. else if (data == "false")
  55. {
  56. $('#divTitle').css("background-color", "#FF0000");
  57. $('#msgHeader').text("Error!");
  58. $('#msgAlert').html("Unable to Change your Password!");

  59. $('#dialogAlert').popup();
  60. $("#dialogAlert").popup("open");
  61. $("#dialogAlert").on("popupafterclose", function( event, ui )
  62. {
  63. $("#txtPassword").val("");
  64. $("#txtRetypePassword").val("");
  65. $("#btnResetPassword").parent().show();
  66. $("#txtPassword").focus();
  67. });
  68. }
  69. }).fail(function(jqXHR, message)
  70. {
  71. alert('Error: ' + message);
  72. })
  73. }
  74. });

Thanks,
Jassim