jQuery Validator with custom method -


i totally new jquery , need add validation form. have select box 3 types of credit card options - visa, mastercard , amex. have text box entering security code on credit card. however, security code required if amex selected.

the select box named "cardtype" , textbox named "securitycode"

so if amex selected nothing entered securitycode textbox, want 1 of jquery red errors appear beneath textbox when tries submit form.

i know has validator.addmethod not know how begin add main.js file.

$.validator.addmethod("securitycode",             function(value, element) {                    var card_type = $("input[name='cardtype']").val();                    if(card_type == "amex" && !$.trim(value) ) {                           return false;                    }                    else {                           return true;                    }               },                  "please ad security code"  ); 

if card type amex , have not entered security code value , can not proceed.

in validation rules , call custom validator

securitycode  {                  securitycode : true                }, 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -