currently I am working on an input field and I want to control the given input.
To set input characters I am using a Regex.
I only want to allow all numbers, letter (capital and normal),"-", ".".
My Regex looks like this in C#:
Regex regex = new Regex(@"[\w.-]+$");
Am I overseeing something?
>Solution :
It looks fine, but you only check end of string not start, should add ^ at beginning. In \w also "_" is valid character, which might give you unexpected results, you could replace it with [a-zA-Z0-9]
Regex regex = new Regex(@"^[a-zA-Z0-9.-]+$");