views:

32

answers:

0

Hi this issue is really effecting me a lot any suggestions are greatly helpful

I need to add the validation in rules so that If i give a value in one field the other fields should also be filled or If I do not give any value in any of the fields it should be ok

This is for my phone number fields I have three fields named as areaCode, exchange and number

this is the below code how I defined it

<div class="pad10Top"><input name="areaCode" id="mobilePhone1" maxlength="3"/><input name="exchange" id="mobilePhone2" maxlength="3"/><input name="number" id="mobilePhone3" maxlength="4"/><a href="javascript: void(0)"><img name="link" id="linkMobilePhoneBtn" name="link" src="images/theme/btn_clear.gif" class="inlineButton" onclick="$('#mobilePhone1').val('');$('#mobilePhone2').val('');$('#mobilePhone3').val('');"/></a></div>

I tried different sinerios for fixing it in rules but did not work out some thing like

rules: {
                areaCode: {
                        digits: true,
                        minlength: 3,
                required: "#exchange:filled"
                },
                exchange: {
                        digits: true,
                        minlength: 3,
                required: "#number:filled"
                },
                number: {
                        digits: true,
                        minlength: 4,
                required: "#areaCode:filled"
                }
        },

I even tried writing a external function and calling it some thing like

function testPhone() {
    if (($("#exchange").val() == "") && ($("#number").val() == "") && ($("#areaCode").val() == ""))
     return false;
    else
     return true;
}

and call it in

required: {
    depends: function(element) {
     return testPhone()
     }
    }

I saw some block where the validation plug in writer wrote some thing like this but this did not work eather

areaCode: { 
        digits: true, 
        minlength: 3, 
        required: "#exchange:filled, #number:filled"

If some one can help with this issue I will be so greatful for them please help me with code as I am fresher thankyou }