I need a regular expression that will only accept numbers from 0-9 and nothing more. No letters, no characters.
I thought this would work:
^[0-9]
or even
\d+
but they accept characters: ^, $, (,), etc.
I thought both of the above expressions would do the trick, and I'm not sure why it accepts these characters.
EDIT:
This is exactly what I am doing:
private void OnTextChanged(object sender, EventArgs e) { if (!System.Text.RegularExpressions.Regex.IsMatch("^[0-9]", textbox.Text)) { textbox.Text = string.Empty; } }
This allows you to use the characters mentioned above.
c # regex
mo alaz Oct 31 '13 at 19:44 2013-10-31 19:44
source share