I wrote Regex to allow only digits. It is @"[0-9]" and it works perfectly. But I would like to add a symbol “-” in regex. I want to allow digits and “-“. How to do it?)
I’ve tried such mask @"[0-9]\{-}" but it allows nothing.
I have seen recently that if I input hyphen then my program does not understand as “hyphen”. This is a reason why your all masks did not work. Nevertheless, they are all correct. Thanks a lot for your help. Now I will find how to read hyphen as “-” in WPF 2010.
Hypens (
-) do not act like range specifiers at the beginning of a character set, so you can do this with the regexor if, like in most regex engines, WPF allows character set shorthands in character sets, you can also use
or, as the other answers mentioned, you can escape the
-to put it in the regex, as in either of these two regular expressions