jQuery validate password fileds same value and length

A short script for jQuery that validates two password fileds so they have the same value and a minimum length.

        <div class="error_messages" id="error-message"></div>
        <script type="text/javascript">
            function validateForm(pwd){
                if($('#txtPwd1').val() != $('#txtPwd2').val()){
                    pwd.addClass('error');
                    $('#error-message').text('<?= $this->translate('Password has to be the same in both fields') ?>');
                    $("#subSave").attr("disabled", "disabled");
                }else if($('#txtPwd1').val().length < 8){
                    $('#error-message').text('<?= $this->translate('Password has to be longer than 8 characters') ?>');
                    $("#subSave").attr("disabled", "disabled");
                }else{
                    $("#subSave").removeAttr("disabled");
                    $('#error-message').text('');
                    $('#txtPwd1').removeClass('error');
                    $('#txtPwd2').removeClass('error');
                }
            }
            $(document).ready(function(){
                $("#subSave").attr("disabled", "disabled");
                $('input:password').keyup(function(){
                    validateForm($(this));  
                });
            });
       
        </script>
Knowledge keywords: