JQuery validation - validation of specific rules / keystrokes for specific fields

Using jquery validation: http://docs.jquery.com/Plugins/Validation

I also check every blur field:

//validate each element on blur
    $('input, select, radio, checkbox').blur(function(){
        $("#createAccount").validate().element(this);
    });

I added an additional method for passwords - alpha, number, spaces / dashes:

//Additional validation methods:
jQuery.validator.addMethod("passwordCheck", function(value, element) {
    return this.optional(element) || /^[a-zA-Z0-9]+$/.test(value);
}, "Invalid characters");

A few problems:

I would like to check the password field for blur for everything except the passwordCheck method. Therefore, other methods, such as those required, should be checked for blur - but if the wrong character is entered, I want the validator to run this method.

In addition, when adding methods, is there a way to get an error message regarding verification request messages (just so that they all are in one place)?

+3
source share
2 answers

, :

, , , - ""

$('.ignore').blur(function(){
        if( $(this).val()=="") {
         $(this).parent().removeClass("inputSuccess");
        }
    });

, , I, . , .

+1

HTML5 required. - :

<input type="password" name="password" required />

return !$(element).hasAttr("required");

. , , , .

http://www.w3.org/WAI/GL/wiki/Techniques/HTML5/Using_the_required_attribute_to_indicate_a_required_input_field

0

All Articles