0

I don´t know how to resolve a situation i have. I have a regular expression that validate a textbox input, what i need is to prevent or remove characters that not mach the regular expresion while the user is typing. my regular expression is:

^[A-Z0-9]+(\.[A-Z0-9]+|[A-Z0-9]*)*$. 

it allows letters,numbers, and dots (but no more than one consecutive), but it can be change without notificacion (by system configuration)

Any idea how to solve it?

Upd: it`s a winforms application

VMAtm
  • 27,943
  • 17
  • 79
  • 125
Müsli
  • 1,744
  • 7
  • 27
  • 50
  • Possible duplicate http://stackoverflow.com/questions/1048710/validating-winforms-textbox-in-c – VMAtm Jun 14 '11 at 13:16

2 Answers2

0

Use Custom validator with this regex.

VMAtm
  • 27,943
  • 17
  • 79
  • 125
0

You could keep a local variable that stores the value of the textbox. On each keypress, check whether the key matches the regex. If so, add the character to the local variable, and set the textbox's text field to the variable. Otherwise set the textbox to the current value of the local variable, thus overwriting the bad input.

DJ Quimby
  • 3,669
  • 25
  • 35