No more than 8 characters else display error

Hi Guys,

How do i check to see if a variable contains 8 numbers. For example.

If $dob == 8 numbers then
echo works
else
echo wrong

Has to be numbers and no text, Any help would be great.

Thanks Guys!

[FPHP]is_int[/FPHP], [FPHP]strlen[/FPHP]

I’d use [fphp]ctype_digit[/fphp] instead of is_int, in case it comes from $_POST of $_GET and is thus a string, and not an int, but numeric nonetheless :slight_smile:

Hi StarLion,

Hope your well today. I’ve tried that but keep getting the is not integer error.


<?php
$dob=$_GET['dob'];

if (is_int($dob)) {
    echo "is integer\
";
} else {
    echo "is not an integer\
";
}

?>

/testdob.php?dob=4

Thanks

Ah, I’ll try this then since thats what I’m doing :slight_smile:

Thank you.

Thanks guys, EDITED: Fixed it :slight_smile:

Is 87654321 an acceptable value for $dob?

No its not but its just an example :slight_smile:

I’ve already coded it to ensure the date entered is valid :slight_smile:

Thanks for pointing it out though.