Try using some RegEx:
Regex reg = new Regex("^[a-zA-Z]-");
bool check = reg.IsMatch("e-rob");
Or even more concise:
if (Regex.IsMatch("e-rob", "^[a-zA-Z]-")) {
// do stuff for when it matches here
}
The ^[a-zA-Z]
is where the magic happens. Breaking it down piece-by-piece:
^
: tells it to start at the beginning of whatever it's checking the pattern against
[a-zA-Z]
: tells it to check for one upper- or lower-case letter between A and Z
-
: tells it to check for a "-" character directly after the letter
So e-rob
or E-rob
would both return true where abcdef-g
would return false
Also, as a note, in order to use RegEx you need to include
using System.Text.RegularExpressions;
in your class file
Here's a great link to teach you a bit about RegEx which is the best tool ever when you're talking about matching patterns