Jump to content

Help with a function..


jscix

Recommended Posts

How could I make this function return a true or false value depending on if the supplied string passes the checks??

 

<?php

Function ValidateString($txtcheck)
{  //start function

if ($txtcheck == (null))
{
// didn't pass because string is null
}

elseif (strlen($txtcheck) < 3)
{
// didn't pass because string is too short

}

elseif (ctype_alnum(!$txtcheck))
{
// didnt pass because string contains alphanumeric chars
}
else
{
// return true
}

} // end function

 

sorry for the easy question, still getting the hang of this stuff. :o anyone?

Link to comment
Share on other sites

Like so...

<?php
function ValidateString($txtcheck) {
    if($txtcheck == (null)) {
        return false;
    } elseif(strlen($txtcheck) < 3) {
        return false;
    } elseif(ctype_alnum(!$txtcheck)) {
        return false;
    } else {
        return true;
    }
}
?>

Link to comment
Share on other sites

Ok, I'm a minimalist and on second thought I realized you could compress this down to a single line:

 

Well done, though, I intentionally re-wrote the function to clearly display the logic, as the original poster appears to be new to the language :)

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.