Checking to see if string starts with an alpha character

Recently I needed to validate a string input by a user to ensure it was in a specific format.  One of the requirements was that the first character of the string had to start with a alpha character (A-Z).  Here is how you can accomplish this:

string alphatag = tag.Substring(0,1);

System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(“[a-zA-Z]”);           
bool isalpha = regex.IsMatch(alphatag);

Utilizing the RegularExpressions class is a very useful tool in comparing values against specific patterns.


Kris Halsrud

Kris Halsrud is a Senior Analyst / Developer for Customer FX Corporation.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) and Creatio (bpm'online) news and product updates!

You have Successfully Subscribed!