got model properties have data annotation validator attributes. typical example be:
[regularexpression("^[a-z]{5,}$", errormessage="required field, must have correct format")] public string someproperty {get;set; }
i need make these validators conditional: if specific property in model has value, validators should disabled. -on both serverside , clientside. ( (i'm using standard ms ajax client side validation)
there's no default way of making data annotation validators conditional i've looked around libraries implement new kinds of data annotation validators. looked @ foolproof.codeplex.com , requiredif validation attribute. found either couldn't implement them or simple in implementation (foolproof lets check single condition)
the best solution me if provide validator 2 parameters: conditional expression , validator. this:
[requiredif("otherproperty == true", regularexpression=@"^[a-z]{5,}$", errormessage="required field, must have correct format")] public string someproperty {get;set; }
any there other libraries recommend, or other types of solutions try?
looks want use regularexpressionif validator foolproof.
Comments
Post a Comment