Java Regex to Validate Full Name allow only Spaces and Letters

前端 未结 14 2543
抹茶落季
抹茶落季 2020-11-28 04:50

I want regex to validate for only letters and spaces. Basically this is to validate full name. Ex: Mr Steve Collins or Steve Collins I tried this regex.

14条回答
  •  甜味超标
    2020-11-28 05:08

    check this out.

    String name validation only accept alphabets and spaces
    public static boolean validateLetters(String txt) {
    
        String regx = "^[a-zA-Z\\s]+$";
        Pattern pattern = Pattern.compile(regx,Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(txt);
        return matcher.find();
    
    }
    

提交回复
热议问题