views:

311

answers:

3

Is there a simples way to do this?

I have 2 TextBox, for email input, with regex and compare validator. If user input invalid email and a different email at second textbox, is shown two error messages. But i want to display just one error message at a time.

+1  A: 

In this case, you might try writing a custom validator to perform the regex first, and only do the comparison validation if the entry passes the regex validation (or the other way around, however you want to do it). There may be a simpler solution, but this is the best way I can think of.

Ender
I agree with Shoban's answer, but if you're insistent on showing them one at a time then Ender's answer is the way to go. In fact, you could build up the error message to indicate both problems. So if your regex match fails, set the error message to "Invalid email format" then if the compare fails and the error message isn't empty you could append " and email verification must match," otherwise set it to "Email verification must match." Of course the user may not bother to read past the 1st portion of such a message and fix 1 prob then get hit with the 2nd, so seperation would be clearer.
Ahmad Mageed
The problem with regex is compare validator
Fujiy
A: 

Nice question but couldnt find a solution for this question. But I would not recommend it. Its always better to show all the required fields error message. Think about a form with lot of input fields and I wouldn't know the error until I scroll down and click the submit button.

What are you going to achieve by limiting the number of error messages displayed?

Shoban
I have a automated form generation. I just choose which attributes I want.When 2 valitadors are shown, the second message is hidden behind another control
Fujiy
+1  A: 

Maybe using ValidationSummary control might help you to solve your problem in a different way. Ok, it won't produce only one error message, but it will place them where you want in your page. Just set the text property of your validation controls to * end place a validationsummary control. Hope this helps.

Canavar