views:

53

answers:

1

This code validates a set of form elements,

var objects = $(".validated").filter(function (){
    return $(this).val() == '';
});

Is there i could also filter for a length of >10, for example?

Thanks!

+2  A: 

Either chain together another filter, or modify the condition.

var objects = $(".validated").filter(function (){
    return $(this).val() == '' || $(this).val().length > 10;
});

Alternatively

var objects = $(".validated").filter(function (){
    return $(this).val() == '';
}).filter(function(){
    return $(this).val().length > 10;
});
Stefan Kendall
neither of these work...
tarnfeld
My first example was wrong, but the second should have worked. You do understand that you're asking to get all elements that are either empty or over 10 characters, right?
Stefan Kendall
Seems to me like you might be looking to grab all elements that AREN'T empty and are LESS THAN 10 characters. Am I corredt?
Stefan Kendall