Java - Regex for Full Name

后端 未结 6 1762
谎友^
谎友^ 2020-12-28 21:40

How can I validate regex for full name? I only want alphabets (no numericals) and only spaces for the regex. This is what I have done so far. Would you please help me fix th

6条回答
  •  -上瘾入骨i
    2020-12-28 22:13

    public static boolean isFullname(String str) {
        return str.matches("^[a-zA-z ]*$");
    }
    

    this method returns true if the string only contains alphabets and spaces.

    But it also return true if the string contains nothing.

提交回复
热议问题