-2

I have using this code for getting price from user

<TextBox Name="txtPrice" PreviewTextInput="NumberValidationTextBox" />

And I am forcing the user to enter only numbers

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

How could I provide format of price too, like :

123,700
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

Testing if a string is correctly formatted as a number with optional thousand-separator:

^\d+(,\d{3})*$

Live demo.

linden2015
  • 887
  • 7
  • 9