ComfyUI Node

isdigit

Digits, including the weird ones

By StableLlama·Created about a year ago·Updated 4 days ago· 48
isdigit
    • BOOLEAN
    string

    Like isdecimal, but looser: digits - including the weird ones. Superscript ², Arabic-Indic numerals, that sort of thing. If you just want to know "is this string all digits," this is the middle ground of the pack's three number checks.

    What it does

    isdigit wraps str.isdigit(). It returns True if every character is a digit and the string has at least one character. The difference from isdecimal is subtle and worth knowing: "²".isdigit() is True (it's a digit), while "²".isdecimal() is False (it's not a decimal number you'd use in arithmetic). For plain "123" both return True - the split only shows up with exotic characters.

    One string input, one BOOLEAN output.

    Why you'd reach for it

    "Can I treat this as a number?" - mostly. "123" passes, "1.5" and "-1" both fail (dot and minus aren't digits), so it's a conservative pre-cast check. In practice, for everyday ASCII you won't feel the difference between isdigit and isdecimal; you'd pick isdigit when you want to accept any Unicode digit, and isdecimal when you want strict base-10.

    Installing

    Part of Basic data handling by StableLlama. In ComfyUI Manager search "Basic data handling" → Install → restart. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
    

    Restart. Zero runtime dependencies - pure stdlib - so the install is instant and conflict-free.

    Where people get burned

    The Unicode looseness, mostly. "٢" (Arabic-Indic two) returns True, and "²" returns True - correct per Python's rules, surprising if you assumed ASCII-only digits. If your downstream only understands 0–9, that's a problem waiting to happen, and you'd want a stricter path. And as with all the is-* number checks: it validates digit characters, not number formatting, so "1.5" and "-9" fail.

    CategoryBasic/STRING/is

    Inputs (1)

    NameTypeDefaultDescription
    stringSTRING

    Outputs (1)

    NameTypeDescription
    BOOLEANBOOLEAN