{"record":{"id":"800418187a10d3d1","repo":"TheAlgorithms/Java","slug":"input-input-contains-not-only-digits-800418","errorCode":null,"errorMessage":"Input '\" + input + \"' contains not only digits","messagePattern":"Input '\" \\+ input \\+ \"' contains not only digits","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/others/Verhoeff.java","lineNumber":164,"sourceCode":"        System.out.println(\"\\nCheck digit generation example:\");\n        var input = \"236\";\n        generateAndPrint(input);\n    }\n\n    private static void checkAndPrint(String input) {\n        String validationResult = Verhoeff.verhoeffCheck(input) ? \"valid\" : \"not valid\";\n        System.out.println(\"Input '\" + input + \"' is \" + validationResult);\n    }\n\n    private static void generateAndPrint(String input) {\n        String result = addVerhoeffChecksum(input);\n        System.out.println(\"Generate and add checksum to initial value '\" + input + \"'. Result: '\" + result + \"'\");\n    }\n\n    private static void checkInput(String input) {\n        Objects.requireNonNull(input);\n        if (!input.matches(\"\\\\d+\")) {\n            throw new IllegalArgumentException(\"Input '\" + input + \"' contains not only digits\");\n        }\n    }\n\n    private static int[] toIntArray(String string) {\n        return string.chars().map(i -> Character.digit(i, 10)).toArray();\n    }\n}\n","sourceCodeStart":146,"sourceCodeEnd":172,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/others/Verhoeff.java#L146-L172","documentation":"Thrown by Verhoeff.checkInput (invoked by verhoeffCheck and addVerhoeffChecksum) when the input string does not match the regex \\d+, i.e. contains any non-digit character or is empty. The Verhoeff algorithm operates purely on decimal digits via dihedral-group multiplication and permutation tables, so letters, spaces, dashes, or a blank string are invalid inputs.","triggerScenarios":"Calling verhoeffCheck or addVerhoeffChecksum with a string containing hyphens (\"123-45\"), spaces, letters, a plus sign, a leading +, or an empty string \"\" (\\d+ requires at least one digit).","commonSituations":"Passing a formatted identification number with separators (e.g. ISBN/Aadhaar-style \"1234 5678 9012\"), user input with whitespace not trimmed, copy-pasted values containing non-breaking spaces, or an empty form field.","solutions":["Strip all non-digit characters from the input before calling: input.replaceAll(\"\\\\D+\", \"\").","Reject or re-prompt empty input upstream so the algorithm never receives \"\".","Validate with input.matches(\"\\\\d+\") (or Character.isDigit on each char) before invoking and surface a user-facing validation error instead of letting the exception propagate.","Ensure the input has at least one digit; note that \\d+ does not match the empty string."],"exampleFix":"// before\nboolean ok = Verhoeff.verhoeffCheck(\"123-456\");\n// after\nString clean = \"123-456\".replaceAll(\"\\\\D+\", \"\");\nboolean ok = clean.isEmpty() ? false : Verhoeff.verhoeffCheck(clean);","handlingStrategy":"validation","validationCode":"String clean = input == null ? \"\" : input.replaceAll(\"\\\\D+\", \"\");\nif (clean.isEmpty()) {\n    // handle empty input in UI/parse layer\n    return;\n}\nboolean ok = Verhoeff.verhoeffCheck(clean);","typeGuard":"static boolean isAllDigits(String s) {\n    return s != null && !s.isEmpty() && s.chars().allMatch(Character::isDigit);\n}","tryCatchPattern":"try {\n    boolean ok = Verhoeff.verhoeffCheck(raw);\n} catch (IllegalArgumentException e) {\n    // surface a user-facing \"invalid format\" message\n}","preventionTips":["Sanitise identifier strings (strip spaces, dashes) at the input boundary.","Reject empty strings explicitly before calling — \\d+ requires at least one digit.","Use Character.isDigit in a loop if regex compilation cost matters."],"tags":["java","input-validation","checksum","verhoeff","regex","illegal-argument"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}