I don't have time to check this out, but maybe something like this:
var val_phone = function ( value, element, params ) {
var phone_fields = [ 'home_phone', 'mobile' ];
var other_field;
while ( other_field = phone_fields.pop() ) {
other_field = "contact_" + other_field;
if ( element.id != other_field ) {
other_field = $( "#" + other_field )[0];
break;
}
}
return Boolean(
value.length == 12 ||
(
value.length == 0 &&
$( other_field ).val().length == 12
)
);
};
$.validator.addMethod( 'contact_phone', val_phone, "You must supply at least one 12-character phone number." );
source
share