I need real numbers in TextBox
. I try my code online here
"^-{0,1}[0-9]{1,3},{0,1}[0-9]{1,2}$"
and its working perfectly, but in my project not working. Please show me how I must do it
I need real numbers in TextBox
. I try my code online here
"^-{0,1}[0-9]{1,3},{0,1}[0-9]{1,2}$"
and its working perfectly, but in my project not working. Please show me how I must do it
Would TryParse
works for you? From MSDN:
Converts the string representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed.
And for you, it could be something like this:
private void c_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
double num;
e.Handled = double.TryParse(e.Text, out num);
// if e.Text is a number, e.Handled will be true and num = e.Text
}