user4393725
user4393725

Reputation:

Regex input only number and backspace

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?

Upvotes: 1

Views: 9423

Answers (1)

Corey
Corey

Reputation: 16564

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]+");

Upvotes: 1

Related Questions