Look into regular expressions: System.Text.RegularExpressions.Regex.
String testString = "ghk234_1";
String regExpString = "[a-zA-Z0-9_]*";
Regex regex = new Regex(regExpString);
Match match = regex.Match(testString);
if(match.Success)
{
}
else
{
}
Best Regards,