Derin Derin - 1 month ago 7
C# Question

C# Regex to allow only alpha numeric

I have the following regex

^[a-zA-Z0-9]+$
which would allow alpha numeric characters. The problem here is that if I enter only numeric character like "897687", then the regex still matches. I don't want that to happen. There should be at least one text character and it should start with a text character. For example like "a343" or "a98bder" or "a4544fgf343"

It would be great if you could help me to improve my regex for this.

Answer

Sounds like you want:

^[a-zA-Z][a-zA-Z0-9]*$