I want to return a bool to check that a string contains letters, numbers as well as spaces and dashes. The letters can be from foreign alphabets and need to accept letters such as é
, à
, î
, or ô
. This is the line of code I have:
if (Regex.IsMatch(this.UserFirstName, @"^[a-zA-Z0-9À-ž_ -]") == false)
{ return false; }
However, it returns true
even if I have a #@!
in the string; here on the image I switched the ^
to see if it makes a difference but it doesn't.
What do I need to change to get the expected result: if there are characters such as #
, @
, or !
in the string then return false
.