I use this IP verification feature that I encountered while browsing, it works well until today I ran into a problem.
For some reason, the function will not check this IP as valid: 203.81.192.26
I'm not too good with regular expressions, so I would appreciate any help on what might be wrong.
If you have another feature, I would appreciate it if you could post this for me.
The code for the function is below:
public static function validateIpAddress($ip_addr) { global $errors; $preg = '#^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}' . '(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$#'; if(preg_match($preg, $ip_addr)) { //now all the intger values are separated $parts = explode(".", $ip_addr); //now we need to check each part can range from 0-255 foreach($parts as $ip_parts) { if(intval($ip_parts) > 255 || intval($ip_parts) < 0) { $errors[] = "ip address is not valid."; return false; } return true; } return true; } else { $errors[] = "please double check the ip address."; return false; } }
source share