0

I am trying to detect whether my string contains the alphabets (a-z & A-Z), and I obtained my answer from this post. But not all string works as expected, take 8+a as an example:

string expression = "8+a";
            if (Regex.IsMatch(expression, @"^[a-zA-Z]+$") == true)
                true;
            else
                false;

This returns false which suppose to be true. How do I make this return true. Thanks!

Community
  • 1
  • 1
Adola
  • 337
  • 1
  • 16

1 Answers1

2

^ Anchors your regex to the start of the string.

$ Anchors to the end of the string.

Remove those and your regex will work.

Also, there is no need to compare a bool value to true because it is done automatically.

Tamás Szabó
  • 1,388
  • 11
  • 23