User Input Validation, enforcing a string containing only letters

后端 未结 4 1235

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:37

    add a method to your code to actually scan for numbers...

    something like this:

    private boolean containsNumbers(String name) {
        char[] chars = name.toCharArray();
        for (char c : chars) {
            if (c > 47 && c < 58) {
                return true;
            }
        }
        return false;
    }
    

提交回复
热议问题