Is there a function to check if a string is too long or too short, I normally end up writing something like this in several places:
if (strlen($input) < 12)
{
echo "Input is too short, minimum is 12 characters (20 max).";
}
elseif(strlen($input) > 20)
{
echo "Input is too long, maximum is 20 characters.";
}
I know you can easily write one but is there one built into PHP?
I normally collect errors as I validate input, so the above code would be written:
$errors = array();
if (strlen($input) < 12)
{
$errors['field_name'] = "Field Name is too short, minimum is 12 characters (20 max).";
}
elseif(strlen($input) > 20)
{
$errors['field_name'] = "Field Name is too long, maximum is 20 characters.";
}
How can that be made into a function ^?