0
votes

I wan to know that how can I find the type of validator through jquery using the function Page_Validators[i].controltovalidate

I have one text box and 2 validators on it (1st required field validator and 2nd regular expression validator)

I need to change color of textbox when required flied validator validates but its working on both validator as Page_Validators return all the validator in page. So I want to differentiate between two validators. need solution that how can i differntiate this.

2

2 Answers

0
votes
for(var i=0; i<Page_Validators.length; i++){    
    switch(Page_Validators[i].evaluationfunction.name){
        case "RequiredFieldValidatorEvaluateIsValid": 
            // do stuff for required field validators
            break;
        case "CustomValidatorEvaluateIsValid": 
            // do stuff for custom validators
            break;
        case "RegularExpressionValidatorEvaluateIsValid": 
            // do stuff for regex validators
            break;
        case "CompareValidatorEvaluateIsValid": 
            // do stuff for compare validators          
            break;
    }
}
0
votes

Just in case you're having to support IE8, you'll have to use this code to check the function name (.name isn't supported):

if(Page_Validators[i].evaluationfunction.toString().indexOf('RequiredFieldValidatorEvaluateIsValid') != -1) {
 // Do stuff here