Tuesday, October 28, 2014

Restrict the Keyboard for Numerical Keyboard for a Text Field in Windows Phone

Restrict the Keyboard for Numerical Keyboard(Number Pad) for a Text Field in Windows Phone

This avoid the user for entering Letters in a field which requires to be entered only numbers.

Set the InputScope to Number.

XAML

<TextBox InputScope="Number" Name="txtPhoneNumber" />

C#


InputScope scope = new InputScope();
InputScopeName name = new InputScopeName();

name.NameValue = InputScopeNameValue.Number;
scope.Names.Add(name);

txtPhoneNumber.InputScope = scope;

Above code snippets taken from this MSDN article which you can review for more information.