C# Regex to allow only alpha numeric

后端 未结 6 390
野的像风
野的像风 2020-12-15 03:45

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\"

6条回答
  •  醉梦人生
    2020-12-15 04:31

    Or slightly less verbose than the accepted answer:

    ^[a-zA-Z][\w]*$
    

    C# regex has character class indicator "\w" for alphanumeric characters, but does not have a character class for just alphabetic (no digits), hence you have to specify class set [a-zA-Z] manually.

提交回复
热议问题