RE: [PHP-DB] Valid IP
You're right, thanks. >Shouldn't it be [0-9] for each of the elements, also? *** Wilmar Pérez Network Administrator Library System Tel: ++57(4)2105145 University of Antioquia Medellín - Colombia 2002 *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Valid IP
On Thu, 26 Sep 2002 11:39:40 -0500 "Wilmar Perez" <[EMAIL PROTECTED]> wrote: > Hello guys > > I know this should be asked in another list but don't want to subcribe just > for a simple question. I apologise in advance if that bothers anyone. > > I'm trying to check valid IPs that come from a form filled by a user so I'm > using the following: If you do not need to check the range, why do not simply use ip2long ? http://www.php.net/manual/en/function.ip2long.php pa -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Valid IP
Shouldn't it be [0-9] for each of the elements, also? What if I want to put 123.012.123.123 or something similar? ---John Holmes... > -Original Message- > From: Wilmar Perez [mailto:[EMAIL PROTECTED]] > Sent: Thursday, September 26, 2002 12:40 PM > To: [EMAIL PROTECTED] > Subject: [PHP-DB] Valid IP > > Hello guys > > I know this should be asked in another list but don't want to subcribe > just > for a simple question. I apologise in advance if that bothers anyone. > > I'm trying to check valid IPs that come from a form filled by a user so > I'm > using the following: > > function valid_ip($ip) > { > //Check whether it is a valid IP > if (ereg("^[1-9]{2,3}+\.[1-9]{2,3}+\.[1-9]{2,3}+\.[1-9]{2,3}+$", $ip)) > return true; > else > return false; > } > > However it just accepts IPs such as xxx.xxx.xxx.xxx Errors arise whith IP > such as xxx.xx.xxx.xxx that is every part of the IP should be 3 numbers > lenght to be accepted making the function not very handy. > > Any idea? > > > *** > Wilmar Pérez > Network Administrator >Library System > Tel: ++57(4)2105145 > University of Antioquia >Medellín - Colombia > 2002 > *** > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Valid IP
Take out those + in your regular expression and it works fine for me, for any format. ---John Holmes... > -Original Message- > From: Wilmar Perez [mailto:[EMAIL PROTECTED]] > Sent: Thursday, September 26, 2002 12:40 PM > To: [EMAIL PROTECTED] > Subject: [PHP-DB] Valid IP > > Hello guys > > I know this should be asked in another list but don't want to subcribe > just > for a simple question. I apologise in advance if that bothers anyone. > > I'm trying to check valid IPs that come from a form filled by a user so > I'm > using the following: > > function valid_ip($ip) > { > //Check whether it is a valid IP > if (ereg("^[1-9]{2,3}+\.[1-9]{2,3}+\.[1-9]{2,3}+\.[1-9]{2,3}+$", $ip)) > return true; > else > return false; > } > > However it just accepts IPs such as xxx.xxx.xxx.xxx Errors arise whith IP > such as xxx.xx.xxx.xxx that is every part of the IP should be 3 numbers > lenght to be accepted making the function not very handy. > > Any idea? > > > *** > Wilmar Pérez > Network Administrator >Library System > Tel: ++57(4)2105145 > University of Antioquia >Medellín - Colombia > 2002 > *** > > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Valid IP
Try this: function padIP($ip){ $ar = explode(".",$ip); $ip = ""; $xt = ""; for ($i = 0; $imailto:[EMAIL PROTECTED]] Sent: Thursday, September 26, 2002 10:40 AM To: [EMAIL PROTECTED] Subject: [PHP-DB] Valid IP Hello guys I know this should be asked in another list but don't want to subcribe just for a simple question. I apologise in advance if that bothers anyone. I'm trying to check valid IPs that come from a form filled by a user so I'm using the following: function valid_ip($ip) { //Check whether it is a valid IP if (ereg("^[1-9]{2,3}+\.[1-9]{2,3}+\.[1-9]{2,3}+\.[1-9]{2,3}+$", $ip)) return true; else return false; } However it just accepts IPs such as xxx.xxx.xxx.xxx Errors arise whith IP such as xxx.xx.xxx.xxx that is every part of the IP should be 3 numbers lenght to be accepted making the function not very handy. Any idea? *** Wilmar Pérez Network Administrator Library System Tel: ++57(4)2105145 University of Antioquia Medellín - Colombia 2002 *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php