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
Loading
Edwin Antonio Arroyo LopezPosted Dec 2, 2009, 8:21 AM
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;
Amit ChoudharyPosted Dec 2, 2009, 12:00 AM
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.