Regular Expression: Allow letters, numbers, and spaces (with at least one letter or number)

后端 未结 8 2046
隐瞒了意图╮
隐瞒了意图╮ 2020-12-08 04:05

I\'m currently using this regex ^[A-Z0-9 _]*$ to accept letters, numbers, spaces and underscores. I need to modify it to require at least one number or letter s

8条回答
  •  难免孤独
    2020-12-08 04:16

    You simply need to specify your current RE, followed by a letter/number followed by your current RE again:

    ^[A-Z0-9 _]*[A-Z0-9][A-Z0-9 _]*$
    

    Since you've now stated they're Javascript REs, there's a useful site here where you can test the RE against input data.

    If you want lowercase letters as well:

    ^[A-Za-z0-9 _]*[A-Za-z0-9][A-Za-z0-9 _]*$
    

提交回复
热议问题