YODA0340 Posted October 24, 2005 Posted October 24, 2005 Hi! I am trying to create a textbox that will only allow certain characters (such as "A" or "V"). For example: -If the user typed in the string "AVVA", then the code would evaluate as true -However if the user added another character "AVVAM" then it would evaluate false. How could this be accomplished? Quote
barski Posted October 24, 2005 Posted October 24, 2005 regex would validate character strings for you. vs magazine had an article implementing this kind of thing a few months ago. do a search on their site and it will provide all the info you need. Quote
bri189a Posted October 24, 2005 Posted October 24, 2005 If the values weren't many you could also just check it on key press and if it wasn't an allowed key then you would cancel the key press. Sometimes regex can be overkill if it's something simple; especially if you don't know regex. Quote
YODA0340 Posted October 25, 2005 Author Posted October 25, 2005 (edited) So what code would i use to determine a keypress and which key was pressed? Edited October 25, 2005 by YODA0340 Quote
Leaders snarfblam Posted October 25, 2005 Leaders Posted October 25, 2005 How about handle the KeyPress or KeyDown event and check the e.KeyChar/e.KeyCode values. To have the control ignore a key, set e.Handled to true. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.