0

I am new to c# and asp.net coding.

I have created a sample page which has a input box and submit button.

I have added regular expression so that the input box takes only numbers.

This is working fine and regular expression is showing error when characters are entered in the field.

But my problem is, when submit button is pressed how I will come to know that validation has been failed for that input box.

How the regular expression result for input box can be accessed when submit button is pressed, so that i will not proceed to save the contents of input box to database

Thanks in advance

Vinayaka Karjigi
  • 1,070
  • 5
  • 13
  • 37
  • Why not disable the submit button in your validation method? And you don't need RegEx for this. Take a look at this question: [How do I make a textbox that only accepts numbers?](http://stackoverflow.com/questions/463299/how-do-i-make-a-textbox-that-only-accepts-numbers) – Alina B. Mar 17 '13 at 03:59
  • One thing to keep in mind is that the user can always disable, or tamper, with your javascript. ALWAYS ALWAYS ALWAYS perform your validation on the server-side as well. Javascript validation is for making the UI more responsive and should not be used as the only validation. – Shai Cohen Mar 17 '13 at 04:47
  • Well that is _how_ the validation controls are designed. The server will inject some js at an appropriate place in the page. It is wired to the submit button's click event. You can observe it in the page's markup. – deostroll Mar 17 '13 at 07:14

1 Answers1

0

If your regular expression is working you could simply put that logic within the button. So when it is pressed the Event Click Notifier does the validation.

Greg
  • 11,302
  • 2
  • 48
  • 79