Java - Regex for Full Name

后端 未结 6 1776
谎友^
谎友^ 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:59

    Use \s for spaces. You can also use String.matches(regex) to test if the string matches a regular expression.

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

提交回复
热议问题