How do you have one asp.net validator tied to multiple controls?

I have 4 text fields that can only take a number. The problem is that I have to create 4 separate validators for the controls and associate their identifier with the validator. Is it possible to have only one asp.net regex validator and associate all controls with this single validator?

+4
source share
2 answers

You can use CustomValidator and write your own verification code. Client code could hypothetically access each text field and check for regular expression ...

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator.aspx

A simpler solution, if you do not want to include the regular expression in 4 places, is to save the regular expression in the code and apply it to all validators during page loading? Not perfect soln, but will work. You can also apply the standard error message and other formatting options in the code.

+5
source

No, because each validator has a controltovalidate property that can only be set to one value. The one exception is CustomValidator

+2
source

Source: https://habr.com/ru/post/1312222/


All Articles