Reputation: 13
How can I check if a string in php contains only lower case characters?
I tried:
if (!preg_match('~[a-z]~', $_POST['name']))
{
$errors[] = 'Caracteres inapropriados!';
}
Thanks!
Upvotes: 1
Views: 1316
Reputation: 34426
You can use this if you're wanting to use regular expressions -
if (!preg_match('^[a-z]+$', $_POST['name']))...
Upvotes: 0
Reputation: 59701
This should work for you:
It return's true if all characters are lower case!
if(ctype_lower($_POST['name']))
echo "All characters are lower case!";
Upvotes: 4