I have a TextBox which should only accept numbers (they can be simple int or float with E as power factor).
So some valid examples are:
1
+1.1
0
.1
1E-1
1e-2
-1.66
-6e-10
non-valid example:
E-1
Generally it should start with either a number or + and – signs or a DOT.
Then I will put this in TextChanged event and it will be fine.
textBox.Text = Regex.Replace(textBox.Text, @"[\d]", ""); //so useless!
If you want your exponents to be used, try this (be sure to add
using System.Globalization;):