Validation of WinForm Data
-
Hi There, I want to be able to validate data entered by a user onto a form. Different fields will have different validation requirements. As an example, a text box may only allow numeric, alpha or alpha numeric entry and/or may have limitations on length or value. I thought about inheriting a control from one of the standard forms controls and adding the validation code required but was thinking that this would make the application heavier than necessary because certain fields only require certain validation. I wanted a way to add validation only where required so thought of creating a validator object which could have various validationRule objects added as required. The validator could respond to events like textChanged on a text box and where it would then check the rules that had been applied. I thought that the validationRule object would be either abstract or impliment specific interface. I like the GOF 'Chain of Responsibility' pattern as a way of getting the rule objects to respond to a message from the validator however, I don't know how to ensure that all the rule objects have received/responded to the message. Does this concept make sense? Is this the best way to go about validating user input? Is this pattern appropriate in this example? Your thoughts/ideas/comments appreciated. Regards Wayne Phipps ____________ Time is the greatest teacher... unfortunately, it kills all of its students View my Blog