Hi everyone... again!
function validateIP($ip)
{
$regexp = "([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})";
$validate = ereg($regexp, $ip);
if ($validate == true)
{
return true;
}
else
{
return false;
}
}
...so here's my IP address validator.
Pretty simple really, it's just it doesn't work all that well.
for example:
validateIP("192.168.1.1"); // returns TRUE
validateIP("999.999.999.999"); // ALSO returns TRUE but it's invalid
So I need to be able to determine the following:
- If the IP is 4 blocks of 3 numbers between 0 and 255, of course, 0.0.0.0 is also invalid.
- If the IP resolves to a hostname
- Any other validations anyone can think of.
maybe we shouldn;t be using regular expresions at all??
Also, I am trying really hard to avoid using these, for sooooo many reasons:
ip2long()
long2ip()