Validate Input Length

I need to make sure the user input is 6 characters long before code is executed.
User input is always “CT” followed by 4 digits ex: CT5469, CT0003, CT0010
Here is what I have.
[php]
$color = $_GET[‘color’];
$color = mysql_real_escape_string($color);
$query = "SELECT * FROM CT_colors WHERE color_id = ‘$color’ ";
$qry_result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($qry_result)){
$display_num = “$row[color_num]”;
$display_id = “$row[color_id]”;
$display_name = “$row[color_name]”;
$display_pic = “$row[color_pic]”;

}
if(strlen($color) = 6)/////doesn’t work
echo $display_num;[/php]

I tried several different things that did not work.
The “if(strlen($color) = 6)” is one of the things that doesn’t work.
I am pretty sure it is something simple…
I just can’t seem to get the answer.
Any help would be greatly appreciated. ;D

Hi there,

Try putting “== 6” rather than “= 6”

Thanks that worked. ;D

Sponsor our Newsletter | Privacy Policy | Terms of Service