Minearena surporte
Minearena surporte

Reputation: 13

PHP - How can I check if a string contains only lower case characters?

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

Answers (2)

Jay Blanchard
Jay Blanchard

Reputation: 34426

You can use this if you're wanting to use regular expressions -

if (!preg_match('^[a-z]+$', $_POST['name']))...

Upvotes: 0

Rizier123
Rizier123

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

Related Questions