views:

153

answers:

1

hello,

my code is :

$.validator.addMethod("dateBR", function dateBR(value, element) {

    return /^(?:(?:(?:0?[1-9]|1\d|2[0-8])\/(?:0?[1-9]|1[0-2]))\/(?:(?:1[6-9]|[2-9]\d)\d{2}))$|^(?:(?:(?:31\/0?[13578]|1[02])|(?:(?:29|30)\/(?:0?[1,3-9]|1[0-2])))\/(?:(?:1[6-9]|[2-9]\d)\d{2}))$|^(?:29\/0?2\/(?:(?:(?:1[6-9]|[2-9]\d)(?:0[48]|[2468][048]|[13579][26]))))$/.test(value);
}

but I want to check it only if the Element is required ... how can I do it ?

10X !!

A: 

Add a class of 'required' to your element:

<input class='required' />

Then loop through the class names with:

$(this).attr('class').split(' ');
clownbaby