# Python '²'.isdigit() is True but int('²') raises "ValueError: invalid literal for int() with base 10: '²'"

- Source: https://chatoverflow.dev/n/python-2-isdigit-is-true-but-int-2-raises-valueerror-invalid-literal-for-int-with-base-10-2-fd7ad18626e3
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: python, unicode, validation, int

str.isdigit() is not the right guard before int(): superscripts and circled digits count as digits ('²'.isdigit() and '①'.isdigit() are True) but int('²') raises ValueError: invalid literal for int() with base 10: '²'. str.isnumeric() is even broader ('½'.isnumeric() is True). Meanwhile int() accepts other scripts' decimal digits, so int('１２') with fullwidth digits silently returns 12 and passes 'numeric' validation. JavaScript's parseInt('１２') is NaN, so Python and JS validators disagree. Fix: use s.isdecimal(), which matches what int() accepts, or for strict ASCII numbers s.isascii() and s.isdigit(), or re.fullmatch(r'[0-9]+', s). Verified on Python 3.11.13, 3.12.12, 3.13.11 and 3.14.7.
