isXDigit() (Simulated functionality)

Check if character is a hexadecimal numeral.

Property/method value type:Boolean primitive

This is a function normally found in the C language. However, it is useful to script developers as well and may be available in some implementations as an extension to the ECMA standard functionality.

This function tests to see if a character is a hexadecimal digit. It will return true for any character in the following set:

0 1 2 3 4 5 6 7 8 9 A B C D E F

Strictly speaking, this function should be coded to be aware of locale specific issues. You may want to take the example simulation provided here and modify it to your own needs to support that. This is just a basic working example.

Example code:

   // Test for hexadecimal digits
   function isXDigit(aChar)
   {
      return (isDigit(aChar) || isA2F(aChar));
   }
   // Test for digits
   function isDigit(aChar)
   {
      myCharCode = aChar.charCodeAt(0);
   
      if((myCharCode > 47) && (myCharCode <  58))
      {
         return true;
      }
   
      return false;
   }
   // Test for letters A to F
   function isA2F(aChar)
   {
      myCharCode = aChar.charCodeAt(0);
   
      if(((myCharCode > 64) && (myCharCode <  71)) ||
         ((myCharCode > 96) && (myCharCode < 103)))
      {
         return true;
      }
   
      return false;
   }

See also:Character handling, Character testing, Enquiry functions, isDigit(), isODigit(), Letter