Grzegorz Węgorzewski Grzegorz Węgorzewski - 5 months ago 51
jQuery Question

How to validate php md5 string with jquery validate

I have string (md5 php) and i want to valid that with jquery validation with md5 jquery plugin https://github.com/placemarker/jQuery-MD5.

Html code

<input type="password" name="token" id="token">
<input type="hidden" name="hiddenToken" id="hiddenToken">


Jquery code

var rules = rules:{
token: {
required : true,
equalTo: "#hiddenToken"
}
}


and also

$("#token").on("keyup", function(){
var md5 = $.md5($(this).val());
})


When im console log those string are identical.
Any one knows why jquery validate give me an error token invalid

Answer

I think that the actual value of the token field (not hashed) is compared to the hash of the hiddenToken field. And so it is clear that you get an error because they are surely not the same.

You could try to change the code after on keyup to:

$("#token").on("keyup", function(){
    $(this).val($.md5($(this).val()));
})

Probably it will work but I could not have tested it.