C# Regex to allow only alpha numeric

后端 未结 6 405
野的像风
野的像风 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:33

    Sounds like you want:

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

    EXPLANATION

    ^ asserts position at the start of a line

    Match a single character present in the list below [a-zA-Z]

    » a-z a single character in the range between a (index 97) and z (index 122) (case sensitive)

    » A-Z a single character in the range between A (index 65) and Z (index 90) (case sensitive)

    Match a single character present in the list below [a-zA-Z0-9]*

    * Quantifier — Matches between zero and unlimited times, as many times as possible, giving back as needed (greedy)

    a-z a single character in the range between a (index 97) and z (index 122) (case sensitive)

    A-Z a single character in the range between A (index 65) and Z (index 90) (case sensitive)

    0-9 a single character in the range between 0 (index 48) and 9 (index 57) (case sensitive)

    $ asserts position at the end of a line

    Demo

提交回复
热议问题