note 31192 deleted from function.ereg by irchtml

From: Date: Wed, 25 Feb 2004 17:34:20 +0000
Subject: note 31192 deleted from function.ereg by irchtml
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-65746@lists.php.net to get a copy of this message
Note Submitter: caleb_ownz@yahoo.com ---- hey, I needed a simple check to see if a string is some kind of IP Address.. (IPv6, IPv4, LongIP) Here is an example: if (ereg("^([0-9]{1,3}(\.[0-9]{1,3}){3})$| ^([0-9]{8,10})$| ^([0-9a-fA-F]{0,4}(:[0-9a-fA-F]{0,4}) {2,7}(([0-9]{1,3}(\.[0-9]{1,3}){3})?| (/[0-9]+)?))$", "127.0.0.1")) { echo "correct"; } (line wrapped) This isn't perfect at all, for example, ips such as 324.552.112.33 will be accepeted too. (same for longips) here are the regex broken apart: Ip4v detection: ^([0-9]{1,3}(\.[0-9]{1,3}){3})$ longip detection: ^([0-9]{8,10})$ ipv6 detection: ^([0-9a-fA-F]{0,4}(:[0-9a-fA-F]{0,4}){2,7} (([0-9]{1,3}(\.[0-9]{1,3}){3})?|(/[0-9]+)?))$ If you have a better way please tell me. Thanks.

« previous php.notes (#65746) next »