PHP makes it so easy
no regex, no clutz
just use
filter_var($ip, FILTER_VALIDATE_IP)
where $ip is the string containing the address
returns TRUE if valid
of course if you like to suffer horribly, skip filter_var() and use preg_match() which goes away
real soon...
function checkIPAddress($ipAddress)
{
return preg_match('/^(?:25[0-5]|2[0-4]d|1dd|[1-9]d|d)(?:[.](?:25[0-5]|2[0-4]d|1dd|[1-9]d|d)){3}$/',
$ipAddress);
}
No hay comentarios:
Publicar un comentario