0

I have a case where i need to allow Alphanumeric but 1st letter of the string should always be Alphabet only

Below is sample case

string text1 = "A1222"; Valid
string text2 = "1A22"; // Invalid

1 Answers1

1

A variant of what was already said in the comments would be

Regex reg = new Regex(@"^[a-z][a-z\d]*$", RegexOptions.IgnoreCase);

That one is not particularly complex, but for complex ones it is very nice making them case insensitive.

Warning: Do note that [A-z] would yield wrong results as mentioned in this related question Difference between regex [A-z] and [a-zA-Z]

Cleptus
  • 3,446
  • 4
  • 28
  • 34