In my windows phone7(silverlight) application I have to restrict inserting symbols for a textbox. Basically I need only to allow inserting alphanumeric characters.
So as the first step I added
InputScope="AlphanumericHalfWidth" and then InputScope="AlphanumericFullWidth".
But in both the situations, the keyboard shows and allows to enter the following characters and many more. @ # $ % & % ( ) !
Therefore I just implemented the following logic in the text box KeyDown event
if (!( (e.PlatformKeyCode >= 48 && e.PlatformKeyCode <= 57) || (e.PlatformKeyCode >= 65 && e.PlatformKeyCode <= 90) || (e.PlatformKeyCode >= 97 && e.PlatformKeyCode <= 122)))
{
e.Handled = true;
}
But the thing is It still allows to enter the following characters for the textbox. @ # $ % & % ( ) !
Can’t figure out how exactly I have to achieve this. If someone can guide me a way to restrict all the other characters except alphanumeric to be inserted for the textbox, would really appreciate. Thanks….
This is because PlatformKeyCode are not ASCII values, which you are trying to handle.
Use TextChanged event handler:
where bla is the textbox name.