Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP uppercase letter in String

Tags:

php

uppercase

Like the title says, I'm looking for a way to check if a string contains an uppercase letter in it. It is for a password field, and I cannot use regex because we have not learned any of that yet in class.

I tried to use ctype_upper but that only seems to work if every character in the string is uppercase.

Is there a way to check any character in a string, but not using regex?

like image 263
Gurpal Rattu Avatar asked May 03 '26 03:05

Gurpal Rattu


1 Answers

You can try this:

if (strtolower($string) != $string) {
    echo 'You have uppercase in your string';
} else {
    echo 'You have no uppercase in your string';
}

This checks if the converted string to lowercase is equal to the original string. Hope this helps...

like image 70
Cedric Avatar answered May 05 '26 03:05

Cedric