If you don't want to allow any other characters entry except for the alphanumeric characters in a TextBox, then you can do this on the KeyPress event of a TextBox.
In the KeyPress Event, you need to check whether the entered character is either a Letter or a Digit.
Char.IsLetterOrDigit(e.KeyChar)
If yes, then allow the Key pressing by setting
"e.Handled = false"
Otherwise, don't allow the Key pressing by setting "e.Handled = true"
In addition to the alphanumeric characters, generally one should allow the backspace character too along with the alphanumeric characters so that the user can remove any wrong character if he entered by mistake.
In order to do that, you need to add one more condition in the if block as
private void textBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (Char.IsLetterOrDigit(e.KeyChar) // Allowing only any letter OR Digit
||e.KeyChar == '\b') // Allowing BackSpace character
{
e.Handled = false;
}
else
{
e.Handled = true;
}
}

Ammar ShaukatPosted Aug 4, 2015, 3:06 AM
Very Helping Thanks..
Harshit ChauhanPosted Jul 22, 2015, 6:11 AM
I don't get any working solution to restrict textbox to alphanumeric only in windows phone 8.1 app from the past 7 days. Can you suggest me any method to handle this. Thanks for the previous help.
Harshit ChauhanPosted Jul 18, 2015, 1:18 PM
How to add defenition of KeyChar in Windows. UI.Xaml.Input.KeyRoutedEventArgs or any other directive is to be used... I am working on windows phone 8.1 project
Harshit ChauhanPosted Jul 18, 2015, 11:45 AM
How to restrict a user not to copy-paste text into the textbox
Ammar HassanPosted Mar 30, 2015, 7:15 PM
how to use this method? mean to say where from to call this method . Which arguments i've to pass into the function ?