Re: validates characters
From: John Harrison (john_andronicus_at_hotmail.com)
Date: 07/28/04
- Next message: Dennis Pais: "Function Template Question"
- Previous message: Lyle Ladeira: "Re: validates characters"
- In reply to: Lyle Ladeira: "Re: validates characters"
- Next in thread: Lyle Ladeira: "Re: validates characters"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 28 Jul 2004 12:46:22 +0100
"Lyle Ladeira" <ladeiras@mweb.co.za> wrote in message
news:ce826t$kqp$1@ctb-nnrp2.saix.net...
> hey
>
> the only thing that should be valid is letters and spaces
> A-Z a-z and spaces, tabes etc...
>
> thanx
>
OK, the way to do this is to loop through all the characters of the string
testing each one. As soon as you find an invalid character then you know
that the whole string is invalid. If you don't find an invalid character
then the string is valid. Something like this
#include <ctype.h>
bool is_valid(const char* str)
{
while (*str)
{
if (!isalpha(*str) && !isspace(*str)) // if not alphabetic and not a
space ...
return false; // .. then its not valid
++str;
}
return true; // all chars tested ok so its valid
}
john
- Next message: Dennis Pais: "Function Template Question"
- Previous message: Lyle Ladeira: "Re: validates characters"
- In reply to: Lyle Ladeira: "Re: validates characters"
- Next in thread: Lyle Ladeira: "Re: validates characters"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|