开发者

textbox prevent some keys

开发者 https://www.devze.com 2023-03-12 14:35 出处:网络
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

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?

U开发者_高级运维pd: it`s a winforms application


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.


Use Custom validator with this regex.

0

精彩评论

暂无评论...
验证码 换一张
取 消