Checking for all lower case or upper case by using ctype_lower() and ctype_upper()

Checking for presence of only lower case or only upper case letters by using ctype_lower() and ctype_upper()
We can check a string to know if all characters present are in lower case letters or not. Some time we may have to ask either in lower case or upper case letter to use. By using ctype_lower() function we will check and display message to user. Syntax :
ctype_lower ( string );
Return value will be TRUE or FALSE.

Here is the code using ctype_lower()
$string='abcasdf';

if (ctype_lower($string)) {
echo " All characters are Lower case only ";
}else{
echo " Not all characters are lower case  ";
}
The output of above code will be
All characters are Lower case only

Presence of Blank space

This function checks for lower cases chars only so presence of any blank space will return as FALSE only.
$string='abc asdf';

if (ctype_lower($string)) {
echo " All characters are Lower case only ";
}else{
echo " Not all characters are lower case  ";
}
Output will be
Not all characters are lower case

Presence of Special characters

Presence of Special characters will also return FALSE , only change the string part like this in above code.
$string='abc)asdf';
Output will be
Not all characters are lower case

ctype_upper : to check Upper case letters

We can check if all chars present in a string are upper case or not by using ctype_upper() function. This function returns TRUE or FALSE based on the string.
Here is the code
$string='ABCDEFGH';

if (ctype_upper($string)) {
echo " All characters are Upper  case only ";
}else{
echo " Not all characters are Upper  case  ";
}
Output is here
All characters are Upper  case only
This function will retrun FALSE if any space or special characters are present inside the string.

Underscore and Dot

This will return FALSE for underscore and dot if present inside the string.

Check for at least one lower case or one upper case

We may ask user to enter at least one Upper case letter or one lower case letter or one special character in a string variable.

Subscribe to our mailing list

* indicates required
Subscribe to plus2net
Your Rating


Google+

PHP String Functions

Post Comment This is for short comments only. Use the forum for more discussions.




Subscribe to our mailing list

* indicates required
Subscribe to plus2net
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us
©2000-2017 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer