FILTER_VALIDATE_IP

FILTER_VALIDATE_IP can be used to validate IP address ( both IPv4 and IPv6 ) . This filter id = 275. Here is the code.

$ip="255.255.47.12";
if(filter_var($ip,FILTER_VALIDATE_IP)){
echo " Correct , validation passed";
}else{
echo " Wrong , validation failed ";
}

To check IPV6 we can add optional flag like this

if(filter_var($ip,FILTER_VALIDATE_IP,FILTER_FLAG_IPV6)){
echo " Correct , validation passed";
}else{
echo " Wrong , validation failed ";
}

Be the first to post comment on this article :


Google+

Post Comment This is for short comments only. Use the forum for more discussions.






OPINION POLL

What is the most important factor of a web site
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us
©2000-2015 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer