Checking string for symbols

Posted by Zeno on Sun 13 Feb 2005 07:52 PM — 4 posts, 17,368 views.

USA #0
I want to check if a string to make sure that it only consists of spaces, letters, and numbers. I did something like this:
     for ( let = argument; *let != '\0'; let++ )
     {
         if ( !isalpha(*let) )
         {
             send_to_char( "The clan name must only have letters in it.\n\r", ch );
             return;
         }
     }


But a space would mean isalpha returns FALSE. Is there another function to use?
USA #1
Yes. You can add a call to isspace() and it should do the trick.

Like so:


     for ( let = argument; *let != '\0'; let++ )
     {
         if ( !isalpha(*let) && !isspace(*let) )
         {
             send_to_char( "The clan name must only have letters in it.\n\r", ch );
             return;
         }
     }
Australia #2
If you want numbers too you'll probably want to use isalnum() instead of isalpha().

Dave
USA #3
*nod* I've decided to disallow numbers anyways.