i have validation rule common many properties i'd centralize dry, while notempty() rules , work fine, matches(...) , other string-only validator rules don't compile.
no problem:
public static irulebuilderoptions<t, tproperty> mustnotcontainhtml<t, tproperty>(this irulebuilderoptions<t, tproperty> rulebuilder) { return rulebuilder.notempty().withmessage("some message."); } understandably won't compile because uses matches(...) string-only:
public static irulebuilderoptions<t, tproperty> mustnotcontainhtml<t, tproperty>(this irulebuilderoptions<t, tproperty> rulebuilder) { return rulebuilder.matches("<[a-z!/?]|&#").withmessage("'{propertyname}' contains special html characters not allowed."); } what rule builder signature there available string-only options?
the solution reuse actual regularexpressionvalidator:
public static irulebuilderoptions<t, string> mustnotcontainhtml<t>(this irulebuilder<t, string> rulebuilder) { return rulebuilder.setvalidator(new regularexpressionvalidator("<[a-z!/?]|&#")).withmessage("some custom message."); }
Comments
Post a Comment