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

后端 未结 8 2021
隐瞒了意图╮
隐瞒了意图╮ 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:20

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

    You can optionally have some spaces or underscores up front, then you need one letter or number, and then an arbitrary number of numbers, letters, spaces or underscores after that.

    Something that contains only spaces and underscores will fail the [A-Z0-9] portion.

提交回复
热议问题