0

i am working on reading the user input from textbox. Textbox should accept only numeric and it is working fine. but its taking only single digit as the input. if i enter two digit number in textbox, it is assigning the last digit as the value.

Ex : input is 25. value gets assigned from textbox is 5.

How can i assign full number from textbox.

 private void Val(object sender, TextCompositionEventArgs e)
    {
        var textBox = sender as TextBox;
        e.Handled = Regex.IsMatch(e.Text, "[^0-9]+");
        if (!e.Handled)
        {
            value = Int32.Parse(e.Text);
        }
    } 
Abhishek
  • 71
  • 8

1 Answers1

1
"^\d+$" 

This argument would include multiple digits. If the digits have to be Arabic specific (0-9) this should work"^[0-9]+$"

You can read about it more in a previous discussion here Regex for numbers only

DavvveN
  • 43
  • 7
  • it is not working. its blank when i enter any numerical value.its not accepting any value. 'Regex.IsMatch(e.Text, @"^\d+$");' – Abhishek May 10 '21 at 12:32