Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check if a users input is a valid IP address or not?

Tags:

I want to check if an entered input is a valid IP address or not. I would like a specific function that will help me validate a users input.

like image 326
Sanjay dev Avatar asked Jun 02 '11 06:06

Sanjay dev


People also ask

What makes an IP address valid or invalid?

A few of the common reasons why an IP address becomes invalid are using reserved IP address ranges, using invalid IP addresses, using non-standard IP address formats, outdated IP addresses, DNS configuration issues, network card problems, and IP address conflicts.

How do you check IP address is valid or not in Java?

We can use InetAddressValidator class that provides the following validation methods to validate an IPv4 or IPv6 address. isValid(inetAddress) : Returns true if the specified string is a valid IPv4 or IPv6 address. isValidInet4Address(inet4Address) : Returns true if the specified string is a valid IPv4 address.


1 Answers

filter_var($ip, FILTER_VALIDATE_IP) 

http://www.php.net/filter_var

Example:-

if(filter_var($ip, FILTER_VALIDATE_IP)){   echo 'Valid IP'; } else {   echo 'Not Valid IP'; } 
like image 54
deceze Avatar answered Sep 22 '22 22:09

deceze