Java - Regex for Full Name

后端 未结 6 1756
谎友^
谎友^ 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条回答
  •  無奈伤痛
    2020-12-28 21:46

    This method validate the name and return false if the name has nothing or has numbers or special characters:

    public static boolean isFullname(String str) {
        String expression = "^[a-zA-Z\\s]+"; 
        return str.matches(expression);        
    }
    

提交回复
热议问题