{"record":{"id":"f6fd692eae5f8617","repo":"TheAlgorithms/Java","slug":"input-input-contains-not-only-digits","errorCode":null,"errorMessage":"Input '{input}' contains not only digits","messagePattern":"Input '(.+?)' contains not only digits","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/others/Damm.java","lineNumber":109,"sourceCode":"        System.out.println(\"\\nCheck digit generation example:\");\n        var input = \"572\";\n        generateAndPrint(input);\n    }\n\n    private static void checkAndPrint(String input) {\n        String validationResult = Damm.dammCheck(input) ? \"valid\" : \"not valid\";\n        System.out.println(\"Input '\" + input + \"' is \" + validationResult);\n    }\n\n    private static void generateAndPrint(String input) {\n        String result = addDammChecksum(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":91,"sourceCodeEnd":117,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/others/Damm.java#L91-L117","documentation":"Thrown by Damm.checkInput when the input string does not match the regex \\d+ (one or more decimal digits). The Damm algorithm computes a check digit using a quasigroup operation table and requires a purely numeric input string; any non-digit character (letter, space, dash, sign, decimal point) is rejected. The message echoes the offending input verbatim.","triggerScenarios":"Calling Damm.dammCheck/addDammChecksum with a string containing letters, whitespace, a leading sign (+/-), a decimal point, or formatting characters (dashes in a pseudo-account number). An empty string also fails \\d+ (which requires at least one digit).","commonSituations":"Passing a formatted identifier (e.g., \"123-456\"), a numeric string with a leading '+', a value with surrounding whitespace, or a value that is actually alphanumeric.","solutions":["Strip non-digit characters and whitespace before calling: input.replaceAll(\"\\\\D+\", \"\").","Reject or normalize formatted identifiers (remove dashes/spaces) upstream.","Validate with your own \\d+ check first to give a clearer error context."],"exampleFix":"// before\nString id = \"123-456-789\";\nDamm.dammCheck(id); // throws: contains dashes\n\n// after\nString id = \"123-456-789\".replaceAll(\"\\\\D+\", \"\");\nboolean ok = Damm.dammCheck(id);","handlingStrategy":"validation","validationCode":"String digits = input == null ? \"\" : input.replaceAll(\"\\\\D+\", \"\");\nif (digits.isEmpty()) {\n    throw new IllegalArgumentException(\"Input has no digits: \" + input);\n}\nboolean ok = Damm.dammCheck(digits);","typeGuard":"static boolean isAllDigits(String s) {\n    return s != null && s.matches(\"\\\\d+\");\n}","tryCatchPattern":null,"preventionTips":["Strip formatting characters (dashes, spaces) before checksumming.","Validate identifiers are numeric at the point of ingestion."],"tags":["checksum","validation","damm","input-validation","string"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}