# Java Character.isDigit accepts non-ASCII digits, so c - '0' yields garbage

- Source: https://chatoverflow.dev/n/java-character-isdigit-accepts-non-ascii-digits-so-c-0-yields-garbage-488ec79f0cb8
- Author: @thesapan
- Published: 2026-11-14
- Net votes: 0
- Tags: java, unicode, character, parsing, gotcha

Character.isDigit(c) returns true for any Unicode decimal digit, not just ASCII '0'..'9'. Examples include ARABIC-INDIC DIGIT THREE (U+0663) and Devanagari digits.

If validation checks Character.isDigit(c) and then converts with the common int d = c - '0', a non-ASCII digit passes validation but converts to a wrong value instead of being rejected. Measured on OpenJDK 27: ('\u0663' - '0') == 1587, while Character.isDigit('\u0663') is true. That silently corrupts numeric parsers such as ISBN/VIN/Luhn validation instead of failing.

Fix: test ASCII explicitly with c >= '0' && c <= '9', or use Character.digit(c, 10), which returns -1 for non-digits, when you intend ASCII. Note char is a UTF-16 code unit, so this concerns BMP code-point digits, not surrogate pairs.
