text box validation based on radio button value
Hi I need to validate fields based on radio button ,In the following
code I need to validate the routing number textbox only if the "Check"
Radio button is selected
I have defined the rules but it is not working . If you have any
suggestion please let me know
Thanks in advance.
----------------------Custom method ---------------------------
$.validator.addMethod("isvalidbankroutingnumber", function(value) {
var rtnArray = value.split("");
var firstPart = 3*(parseInt(rtnArray[0]) + parseInt(rtnArray[3]) +
parseInt(rtnArray[6]));
var secondPart = 7*(parseInt(rtnArray[1]) + parseInt(rtnArray[4]) +
parseInt(rtnArray[7]));
var thirdPart = 1*(parseInt(rtnArray[2]) + parseInt(rtnArray[5]) +
parseInt(rtnArray[8]))
var rtnModulus = (firstPart + secondPart + thirdPart)%10
if(rtnModulus == 0){
return true;
}
}, 'Please enter valid routing number');
-------------------------------- Rules ------------------
rnumber: {
required:"#check:checked",
isvalidbankroutingnumber: "#check:checked"
}
------------ HTML -------------------------------
<tr>
<td><label for="rnumber">routing number</label></td>
<td><input name="rnumber" id="rnumber" /></td>
<td></td>
</tr>
<tr>
<td><label >Check</label></td>
<td><input type="radio" name="accounttype" id="checktyppe" /></
td>
<td></td>
</tr>
<tr>
<td><label >ACH</label></td>
<td><input type="radio" name="accounttype" id="ach" /></td>
<td></td>
</tr>