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

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

    This will validate against special characters and leading and trailing spaces:

    var strString = "Your String";
    
    strString.match(/^[A-Za-z0-9][A-Za-z0-9 ]\*[A-Za-z0-9]\*$/)
    

提交回复
热议问题