Do you need create a method in jquery.validation for this.
Look this example for helping:
Question
I ValidationAttribute below, which validates the information in two fields. It works, but always doing post. In client-side is not working.
What should I switch to ValidationAttribute work on client-side?
[AttributeUsageAttribute(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false)]
public class SexoComTipoPessoa : ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
var property = validationContext.ObjectInstance.GetType().GetProperty("TipoPessoaID");
if (property == null)
return new ValidationResult("Propriedade desconhecida: 'TipoPessoaID'");
var propertyValue = property.GetValue(validationContext.ObjectInstance, null);
/* Tipo de pessoa 2 - é pessoa juridicia */
if (Convert.ToInt32(propertyValue) == 2)
{
if (Convert.ToInt32(value) != 3)
return new ValidationResult("Para o tipo de pessoa 'Juridíca', deve ser selecionado o sexo 'Não aplicavél'!");
}
else if (Convert.ToInt32(propertyValue) == 1)
{
if (Convert.ToInt32(value) == 3)
return new ValidationResult("Para o tipo de pessoa 'Física', deve ser selecionado o sexo 'Masculino' ou 'Feminino'!");
}
return ValidationResult.Success;
}
}
Solution
Do you need create a method in jquery.validation for this.
Look this example for helping: