Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking a string for Mixed Case! Pls Help 1

Status
Not open for further replies.

Forri

Programmer
Joined
Oct 29, 2003
Messages
479
Location
MT
Hi

I would like to know an easy way to verify if a string is made up of Mixed Case (upper and Lower Case)!? is it possible


Thanks
ncik
 
Hi,

Can't find a PHP function to do just that. However, you can make one using [tt]preg_match[/tt]. Try this:

Code:
<?php

  function mixedCases($text) {
    if(preg_match("([A-Z])", $text))
      $upperCaseChars = true;
    else
      $upperCaseChars = false;

    if(preg_match("([a-z])", $text))
      $lowerCaseChars = true;
    else
      $lowerCaseChars = false;
   
    if($upperCaseChars && $lowerCaseChars)
      return true;
    else
      return false;
  }

$mixed = "ABCz";

if(mixedCases($mixed))
  echo "Mixed Cases in \"$mixed\"";
else
  echo "NOT Mixed Cases in \"$mixed\"";

?>

Good Luck


Jakob c",)
 
great Jakob

Thanks
Nick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top