$string='rtAF78a';
if(preg_match('/[A-Z]/', $string)){
echo " There is at least one Upper Case Characters inside the string ";
}else{
echo " There is no Upper case characters inside the string ";
}
The output is
There is at least one Upper Case Characters inside the string
Syntax
preg_match( $pattern,$subject,&$matches = null, $flags = 0, $offset = 0 )
$pattern : The pattern to search forif(preg_match('/[a-z]/', $string)){
echo " There is at least one lower Case Characters inside the string ";
}else{
echo " There is no lower case characters inside ";
}
Output is
There is at least one lower Case Characters inside the string
$string='rtAF 78a';
if (strstr($string,' ')) {
echo " There is at least one blank space present inside the string ";
}else{
echo " There is NO blank space present inside the string ";
}
Output is
There is blank (space) present inside the string
$string='rtAF 78a';
if (preg_match('/[\'^$%&*()}{@#~?><>,|=_+-]/', $string)) {
echo " There is at least one special characters present inside the string";
}else{
echo " There is no special characters present in the string ";
}
There is no special characters present in the string
We have seen how to check for all the upper case letters or all lower case letters ( or special chars ) presence in a string variable. However we may need a situation where we have to ask the user (while entering password ) to enter at least one lower case letter or one upper case letter or one special characters.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.