|
Posted by shimmyshack on 10/27/07 20:58
On Oct 27, 9:39 pm, 182...@rock.com wrote:
> <?php
>
> $testcase = 'AKLWC139';
>
> if (ctype_upper($testcase)) {
> echo "The string $testcase consists of all uppercase letters.
> \n";
> } else {
> echo "The string $testcase does not consist of all uppercase
> letters.\n";
> }
>
> ?>
>
> This is some code that will check a string and validate if it consists
> of all uppercase letters. I am not too familiar with syntax of PHP as
> I am learning, ... can someone please show me a way to make this, so
> it dives a little deeper into checking, and instead checks to see if
> part of the string contains two or more consecutive uppercase
> letters? Like
>
> 'akwSKWsm' would return positive,.... but 'aKwskWsm' would not.
>
> I don't know how this would work, but it seems approachable. Can
> someone pls. help me?
>
> Thank you in advance for assistance. Have a very good day.
you need
ereg()
or one of the preg_
regular expressions, google for
"ereg php function"
to see many examples of its power.
you could use
ereg( '^[a-zA-Z0-9]*[A-Z]{2,}[a-zA-Z0-9]*$', $testcase );
this means
at the start of testcase ^
zero ore more * characters of type a-z or A-Z or 0-9
followed by 2 or more {2,} characters within A-Z range
ended $
by zero or more a-z A-Z or 0-9 characters.
you can even make SURE that the conditions are complied with by using
ereg_replace()
[Back to original message]
|