I have 4 textboxes which can only take a number. The problem is that I have to create 4 separate validators for the controls and associate their id with the validator. Is it possible to have just one asp.net regular expression validator and associate all the controls with that one validator?
Share
You could use
CustomValidatorand write your own validation code. The clientside code could hypothetically access each text box and check them against the regex…http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator.aspx
A simpler solution if you don’t want to have to include the regex in 4 places is to store the regular expression in the code-behind and apply it to all the validators during Page Load? Not a perfect sol’n but would work. You could also apply a standard error message and other formatting options in the code-behind.