Regex allowing a space character in Java

后端 未结 2 1573
长发绾君心
长发绾君心 2020-12-11 03:14

Hey all, so I\'m trying to allow some text input which goes through a regex check before it\'s sent off. I want the text to only include A-Z, 0-9, and the space \" \" charac

2条回答
  •  无人及你
    2020-12-11 03:26

    \s allows for any ASCII whitespace character. Consider using that rather than " ".

    if(!title.matches("[a-zA-Z0-9_\s]+")) {
        //fail
    }
    else {
        //success
    }
    

提交回复
热议问题