public static void MaskNumericInput(object sender, TextCompositionEventArgs e) { e.Handled = !TextIsNumeric(e.Text); } public static void MaskDoubleInput(object sender, TextCompositionEventArgs e) { Regex regex = new Regex("^[.][0-9]+$|^[0-9]*[.]{0,1}[0-9]*$"); e.Handled = !regex.IsMatch((sender as TextBox).Text.Insert((sender as TextBox).SelectionStart, e.Text)); //var dou = 0d; //e.Handled = !IsTextAllowed(e.Text); //e.Handled = true; } private static bool TextIsNumeric(string input) { return input.All(c => Char.IsDigit(c) || Char.IsControl(c)); } private static readonly Regex _regex = new Regex("[^0-9.-]+"); //regex that matches disallowed text private static bool IsTextAllowed(string text) { return !_regex.IsMatch(text); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)