isPunct() (Simulated functionality)

Check if a character is a punctuation mark.

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.

A punctuation character is any character in the isGraph() set except for those in the isAlnum() set.

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 punctuation characters

   function isPunct(aChar)

   {

      return (isGraph(aChar) && !(isAlnum(aChar)));

   }

   // Test for printable characters (only good up to char 127)

   function isGraph(aChar)

   {

      myCharCode = aChar.charCodeAt(0);

   

      if((myCharCode > 32) && (myCharCode <  127))

      { 

         return true;

      }

   

      return false;

   }

   // Test for letters and digits

   function isAlnum(aChar)

   {

      return (isDigit(aChar) || isAlpha(aChar));

   }

   // Test for digits

   function isDigit(aChar)

   {

      myCharCode = aChar.charCodeAt(0);

   

      if((myCharCode > 47) && (myCharCode <  58))

      {

         return true;

      }

   

      return false;

   }

   // Test for letters (only good up to char 127)

   function isAlpha(aChar)

   {

      myCharCode = aChar.charCodeAt(0);

   

      if(((myCharCode > 64) && (myCharCode <  91)) ||

         ((myCharCode > 96) && (myCharCode < 123)))

      {

         return true;

      }

   

      return false;

   }

See also:Character handling, Character testing, Enquiry functions, isAlnum(), isGraph(), Letter