I have searched everywhere and I cannot find a good solution to my problem. I have a regular expression used to validate the text input in an ASP textbox.
Given the fact that this regex is repeated on a number of controls I want to code it once and then call it where it needs to be used. As opposed to repeating the regex across all textboxes, which IMHO is bad practice i.e. if its needs updating then I need to updated it everywhere.
The only possible solution I found was Setting RegularExpressionValidator ValidationExpression at runtime. This does work but I am wondering if it is the only way to do it. The reason being I need to create a RegularExpressionValidator for each textbox control to validate and set the Error message and Expression on each in the Page_Load. Not the end of the world but seems kind of heavy.
Any ideas?
Thanks,
Michael
You could set the value in a
constantorstaticvariable. You could then create a class that inherits from theRegularExpressionValidatorand set the property to that variable or constant.Then your custom derived validator will always have that property set.