isdigit(c::Union{Char,AbstractString}) -> Bool

Tests whether a character is a numeric digit (0-9), or whether this is true for all elements of a string.


  1. Check if a character is a digit:

    julia> isdigit('5')

    This example checks if the character '5' is a numeric digit.

  2. Check if a character is not a digit:

    julia> isdigit('x')

    It returns false for a non-digit character.

  3. Check if all characters in a string are digits:

    julia> isdigit("12345")

    It returns true if all characters in the string are numeric digits.

  4. Check if any character in a string is not a digit:
    julia> isdigit("12x34")

    It returns false if any character in the string is not a digit.

Common mistake example:

julia> isdigit("abc123")
ERROR: MethodError: no method matching isdigit(::String)

In this example, the isdigit function is called with a string as an argument. However, the isdigit function only accepts a Char or AbstractString as input. Ensure that you pass a character or a string to the isdigit function to avoid such errors.

See Also

digits, inf, isdigit, iseven, isfinite, isless, islower, isnumber, isodd, isprime, isqrt, issorted, issubnormal, isxdigit, nan,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field

Checking you are not a robot: