Regular Expression for alphanumeric and underscores

前端 未结 20 969
北荒
北荒 2020-11-22 10:01

I would like to have a regular expression that checks if a string contains only upper and lowercase letters, numbers, and underscores.

20条回答
  •  失恋的感觉
    2020-11-22 10:40

    How about:

    ^([A-Za-z]|[0-9]|_)+$
    

    ...if you want to be explicit, or:

    ^\w+$
    

    ...if you prefer concise (Perl syntax).

提交回复
热议问题