Prosta walidacja textbox

Walidacja tylko liczby

private void NumericOnly(System.Object sender, System.Windows.Input.TextCompositionEventArgs e)
{
            e.Handled = IsTextNumeric(e.Text);
}
 
 
private static bool IsTextNumeric(string str)
{
            System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex("[^0-9]");
            return reg.IsMatch(str);
}

XAMP

<TextBox PreviewTextInput="NumericOnly" />

Poniżej link do obszernego użycia walidacji
http://www.codeproject.com/Articles/15239/Validation-in-Windows-Presentation-Foundation

Kategoria: