Regex input only number and backspace

时间:2015-10-06 08:31:45

标签: c# wpf datagrid

I have a code

private void DataGridTypePayments_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            e.Handled = new Regex("[^0-9]+").IsMatch(e.Text); 
        }

I need input number or backspace.How i can disable input symbol space?

1 个答案:

答案 0 :(得分:1)

The C-style escape for the backspace character is \b which is also the Regex escape for a word boundary. Fortunately you can put it in a character class to change the meaning:

e.Handled = Regex.IsMatch(e.Text, "[0-9\b]+");
相关问题