I am newbie with regex and I want to use preg_match
function to find if a string is an IP adress.
For example if $string = "45.56.78.222"
or something like that , preg_match($regex, $string)
should return true. So, what $regex
should be?
I am newbie with regex and I want to use preg_match
function to find if a string is an IP adress.
For example if $string = "45.56.78.222"
or something like that , preg_match($regex, $string)
should return true. So, what $regex
should be?
Don't use a regex when you don't need to :)
Though if you really do want a regex...
The regex however will only validate the format, the max for any octet is the max for an unsigned byte, or
255
.This is why IPv6 is necessary - an IPv4 address is only 32bits long and the internet is popular :)
should do for your example (which does contain a string that is not an IP address). And of course, it's only an IPv4 address.
This will check for the Perfect Range including if a Range is Higher than 255 from any of 4.