I sank most of last night looking into this and found lots of half answers that didn't quite work for my fairly common issue. I have a Textbox that i want to save to an Integer in a Database. I need to only allow the user to enter valid integers with no spaces so that:
-14 valid
14 valid
0 valid
invalid
14.3 invalid
1-4 invalid
A14 invalid
14A invalid
"14 " (has whitespace) invalid
14 (has whitespace) invalid
1 4 (has whitespace) invalid
you get the picture. only integers.
form what iv'e found this method is the key. but I cant figure out/find the regex/alternative to validate it correctly
private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
//Validation code here
}