Jump to content

Help with tiny function - checking all caps


bjenn85

Recommended Posts

I have a function I call to check if the title of a post is too long as a backup to maxlength on the form. I am now trying to add a simple check and stop the submission if it is in caps. I am just simply looking for the abscence of any lowercase letters, nothing complicated.

 

Here is my snippet below but it's not working I always get the caps error even if the title isn't all caps. What am I doing wrong? Sorry I'm a little new to PHP.

function checktitle($title){
if(strlen($title)>55)
return getmsg('Title Is Too Long');
if(!preg_match('/[a-z]/',$title));
return getmsg('Title Is All Caps');}
Link to comment
Share on other sites

My Opinions:

When you bunch up your code like that it makes it difficult to follow and see where errors may be occurring.

I would enclose conditional statements within braces. Less prone to errors as what happens if you decide to add an additional statement.

If a function or variable name is more than one word long...each successive word should start with a capital letter or an underscore should be used between words for clarity.

function checkTitle( $title )
{
    if(strlen($title) > 55)
    {
        return getMsg('Title Is Too Long');
    }

    if(! preg_match('/[a-z]/', $title))
    {
        return getMsg('Title Is All Caps');
    }
}
Edited by hansford
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.