Home

isalnum

isalnum is a standard library function used to determine whether a character is alphanumeric. It is defined in the C standard library header ctype.h and has the prototype int isalnum(int ch). The function returns a non-zero value if ch is a letter or a digit, and zero otherwise. Its behavior is influenced by the current locale, so the set of characters considered alphanumeric can vary with locale settings.

In the default locale, often referred to as the "C" or "POSIX" locale, isalnum identifies ASCII letters

isalnum is frequently implemented as a macro on many platforms, sometimes backed by a lookup table for

Common uses include input validation and tokenization, such as checking whether a character in a string is

A
through
Z,
a
through
z,
and
digits
0
through
9
as
alphanumeric.
Other
locales
may
treat
additional
characters
as
letters,
affecting
results
accordingly.
The
argument
to
isalnum
must
be
representable
as
an
unsigned
char
or
be
the
special
value
EOF;
passing
a
plain
signed
char
with
a
negative
value
that
is
not
cast
to
unsigned
char
yields
undefined
behavior.
efficiency.
The
wide-character
counterpart
is
iswalnum,
declared
in
wctype.h,
which
operates
on
wchar_t
values.
Locale-aware
variants
can
be
used
by
setting
the
program
locale
with
setlocale
and
by
using
related
locale-aware
functions.
allowed
in
an
identifier
or
username.
A
simple
check
might
evaluate
isalnum(ch)
and
proceed
if
the
result
is
non-zero;
for
example,
it
would
be
true
for
'A'
or
'3'
and
false
for
'%'.