User Input Validation, enforcing a string containing only letters

后端 未结 4 1236

Im trying to make a user input validation system within one of my methods... its working fine to a cetain extent, but despite the code, its still allowing for integers as valid

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-29 10:44

    I will take the code from Ubica. You can do it also like this. It is readable:

    private boolean containsNumbers(String name) {
        char[] chars = name.toCharArray();
        for (char c : chars) {
            if (Character.isDigit(c)) {
                return true;
            }
        }
        return false;
    }
    

提交回复
热议问题