Detect Alphabet only string with ctype_alpha
There are times when you need a function that can detect strings which contains onlyalphabetic characters. While is_numeric can validate a given string contains numeric character, there are no is_* function variation exist which can do the same for alphabetic strings.
However, you can still test for alphabetic string using ctype_alpha() function. Example usage :
if (ctype_alpha($testcase)) {
echo 'The string $testcase consists of all letters.\n';
} else
{
echo 'The string $testcase does not consist of all letters.\n';
}
}
No comments:
Post a Comment