RegularExpressionValidator Problems

curlydog

Well-known member
Joined
Jul 5, 2010
Messages
50
Programming Experience
Beginner
Hi, I have a form on an aspx page with several controls. I have one textbox which is invisible by default, but becomes visible (on postback) if the user chooses a particular value from a dropdownlist.

The textbox (tbAudience) can only contain a whole number. I have two validators pointing at tbAudience. One is a requiredfieldvalidator, the second is a regularexpressionvalidator.

When tbAudience is invisible the requiredfieldvalidator is automatically disabled. I thought I would have to handle this in code, but asp.net appears to automatically disabling the validator as it does not fire if the control is invisible.

My problem lies with the regularexpressionvalidator. The expression to be matched is very simple [0-9]{1,4}. If i type something into tbAudience which fails the test (a word for example) and then tab away from it (so it loses focus), the validator fires and fails.

This is the odd part. If I type the same word into tbAudience and then click on the my submit button, the regularexpressionvalidator does not fire. The page validates, even though tbAudience has a value which fails the expression.

I can't figure out why the regularexpressionvalidator fires when tbAudience loses focus, but not when the submit button is clicked. I have several other requiredfieldvalidators on the same form and they all seem to fire when the submit button is clicked.

Any guidance would be really appreciated. This is my second day trying to figure out this problem.
 
Further to the above, just to illuminate the issue further. If I type a word into tbAudience and tab away from it, the vlidator fires and I see the failure message. If I then click the submit button, this message disappears even though there are other controls on the page that have failed validation, and their failure messages remain on screen.
 
Back
Top