There is a function in the C standard library for this:

    isxdigit

Its manpage says:

              checks for a hexadecimal digits, that is, one of
              0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F.

So, the function can get really short and much more readable.