How to check if only chosen characters are in a string?

后端 未结 4 1415
别跟我提以往
别跟我提以往 2020-12-30 06:19

What\'s the best and easiest way to check if a string only contains the following characters:

abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_         


        
4条回答
  •  萌比男神i
    2020-12-30 06:51

    Use a regular expression, like this one:

    ^[a-zA-Z0-9]+$
    

    http://regexlib.com/REDetails.aspx?regexp_id=1014

提交回复
热议问题