marcus Posted December 17, 2006 Share Posted December 17, 2006 how would i go about checking to see if the IP given is in correct format#dot#dot#dot# Link to comment https://forums.phpfreaks.com/topic/30931-solved-checking-if-ip-is-valid/ Share on other sites More sharing options...
trq Posted December 17, 2006 Share Posted December 17, 2006 [code=php:0]$ip = '192.168.0.1';if (preg_match('\b(((?!\d\d\d)\d+|1\d\d|2[0-4]\d|25[0-5])(\b|\.)){4}',$ip) { // valid.}[/code] Link to comment https://forums.phpfreaks.com/topic/30931-solved-checking-if-ip-is-valid/#findComment-142706 Share on other sites More sharing options...
marcus Posted December 17, 2006 Author Share Posted December 17, 2006 Warning: preg_match() [function.preg-match]: Delimiter must not be alphanumeric or backslash in /home/marcus/public_html/admin/banip.php on line 17The IP provided is not valid Link to comment https://forums.phpfreaks.com/topic/30931-solved-checking-if-ip-is-valid/#findComment-142708 Share on other sites More sharing options...
trq Posted December 17, 2006 Share Posted December 17, 2006 Sorry, might try something simpler.[code=php:0]if (ereg('[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}',$ip)) { // valid}[/code] Link to comment https://forums.phpfreaks.com/topic/30931-solved-checking-if-ip-is-valid/#findComment-142714 Share on other sites More sharing options...
marcus Posted December 17, 2006 Author Share Posted December 17, 2006 Thanks! Works like a charm, +karma for you, haha. Link to comment https://forums.phpfreaks.com/topic/30931-solved-checking-if-ip-is-valid/#findComment-142718 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.