Reputation: 46591
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?
Upvotes: 4
Views: 7903
Reputation: 137128
No, because each validator has a "controltovalidate" property that can only be set to a single value. The only exception is the CustomValidator
Upvotes: 2
Reputation: 13730
You could use CustomValidator
and 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.
Upvotes: 5