I need to validate the fields of my textBox ... In WPF ... Someone could give me a code that works in the KeyDown event ... Or enter special characters not allowed ... I have these two codes:
1 this I agree but also allows ALT numbers and Shipf ... Need only numbers or only letters ...
KeyDown
if
(e.key> = Key.D0 & & e.key <= Key.D9 | | e.key> =
Key.NumPad0 & & e.key <= Key.NumPad9 | | == e.key
Key.Decimal)
e.Handled = false;
else
e.Handled = true;
And this helps us letters and do not know how to modify it to only numbers
Event: KeyDown
Accepted String = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm" + Convert.ToChar (8);
if (Aceptados.Contains ( "" + e.key)) e.Handled = false; else e.Handled = true;
Someone could help
Validations
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Amit ChoudharyRank #145 · 15.8K reputationPosted Dec 1, 2009, 7:00 PM EST
What ever you want just create you accepted string like that... you can append numbers in you string like:
Accepted String="abcdefghijklmnopqrstuvwxyz1234567890";
Now try it again.. if it works.... and if it helps then don't to mark the answer.
Edwin Antonio Arroyo Lopez6 reputationPosted Dec 2, 2009, 3:21 AM EST
in the event ... PreviewTextInput
I hope you can help somebody ...
/ / Call Method IsNumericInput
if (! IsNumericInput (e.Text))
(
e.Handled = true;
return;
)
)
/ / Method allows entry Nemer
private bool IsNumericInput (string p)
(
foreach (char c in p)
(
if (! char.IsDigit (c))
(
return false;
)
)
return true;