If I can assume that the input will be a simple valid IP address and you simply want to know whether you have a port or not, you could do the following:
if (preg_match("/^(?:[0-9.]+|(?:\[[0-9a-fA-F:]+\]))(:[0-9]+)$/", $ip))
{
echo "A port was found.";
}
else
{
echo "A port was not found.";
}
This will match an IP adress like
[2001:0db8:85a3:08d3:1319:8a2e:0370:7344]:8080
or127.0.0.1:8080
but it will not match
2001:0db8:85a3:08d3:1319:8a2e:0370:7344
or127.0.0.1
Keep in mind that the standard defines an IPv6 host to be distinguished by enclosing the IP literal within square brackets.