I have the following in my c# code – what I like it to do is to check to see if the expression has numbers or a dash but nothing else. If I type in the letter K along with a dash or number it still accepts it. How do I say just have the express be numbers or a dash:
Match match = Regex.Match(input, @"[0-9-]");
Note that input is the text that I am passing for evalution.
The
^means that the match should start at the beginning of the input, the$that it should end at the end of the input.The
*means that (only) 0 or more numbers or dashes should be there (use+instead for 1 or more).