Reputation: 185
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
Upvotes: 0
Views: 69
Reputation: 3541
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]
Upvotes: 1