<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Ip address validation in PHP using regular expression</title>
	<atom:link href="http://roshanbh.com.np/2008/04/ip-address-validation-php.html/feed" rel="self" type="application/rss+xml" />
	<link>http://roshanbh.com.np/2008/04/ip-address-validation-php.html</link>
	<description>Useful Tutorials, Scripts , Tips, and Resources for all PHP and Ajax beginners and experts .</description>
	<lastBuildDate>Mon, 07 May 2012 21:11:05 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: shruti joshi</title>
		<link>http://roshanbh.com.np/2008/04/ip-address-validation-php.html/comment-page-1#comment-6821</link>
		<dc:creator>shruti joshi</dc:creator>
		<pubDate>Mon, 16 Apr 2012 02:12:52 +0000</pubDate>
		<guid isPermaLink="false">http://roshanbh.com.np/2008/04/ip-address-validation-php.html#comment-6821</guid>
		<description>Thank you for giving code of IP validation.</description>
		<content:encoded><![CDATA[<p>Thank you for giving code of IP validation.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mihai Voiculescu</title>
		<link>http://roshanbh.com.np/2008/04/ip-address-validation-php.html/comment-page-1#comment-6396</link>
		<dc:creator>Mihai Voiculescu</dc:creator>
		<pubDate>Sun, 06 Feb 2011 14:14:23 +0000</pubDate>
		<guid isPermaLink="false">http://roshanbh.com.np/2008/04/ip-address-validation-php.html#comment-6396</guid>
		<description>Thanks for this code. It is very useful.</description>
		<content:encoded><![CDATA[<p>Thanks for this code. It is very useful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Michael Pedzotti</title>
		<link>http://roshanbh.com.np/2008/04/ip-address-validation-php.html/comment-page-1#comment-5471</link>
		<dc:creator>Michael Pedzotti</dc:creator>
		<pubDate>Sat, 29 May 2010 15:20:09 +0000</pubDate>
		<guid isPermaLink="false">http://roshanbh.com.np/2008/04/ip-address-validation-php.html#comment-5471</guid>
		<description>Thanks for the code sample. It helps me to understand the preg_match command a little bit more.</description>
		<content:encoded><![CDATA[<p>Thanks for the code sample. It helps me to understand the preg_match command a little bit more.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim</title>
		<link>http://roshanbh.com.np/2008/04/ip-address-validation-php.html/comment-page-1#comment-5167</link>
		<dc:creator>Tim</dc:creator>
		<pubDate>Thu, 18 Feb 2010 10:32:11 +0000</pubDate>
		<guid isPermaLink="false">http://roshanbh.com.np/2008/04/ip-address-validation-php.html#comment-5167</guid>
		<description>All of these are rather complex and unless you want a very specific error message why not just use...

function checkIP($ip)
{
	$cIP = ip2long($ip);
	$fIP = long2ip($cIP);
	return $fIP;
}

It will return 0.0.0.0 if an invalid IP or string is passed to it.</description>
		<content:encoded><![CDATA[<p>All of these are rather complex and unless you want a very specific error message why not just use&#8230;</p>
<p>function checkIP($ip)<br />
{<br />
	$cIP = ip2long($ip);<br />
	$fIP = long2ip($cIP);<br />
	return $fIP;<br />
}</p>
<p>It will return 0.0.0.0 if an invalid IP or string is passed to it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: john</title>
		<link>http://roshanbh.com.np/2008/04/ip-address-validation-php.html/comment-page-1#comment-4958</link>
		<dc:creator>john</dc:creator>
		<pubDate>Fri, 18 Dec 2009 11:17:35 +0000</pubDate>
		<guid isPermaLink="false">http://roshanbh.com.np/2008/04/ip-address-validation-php.html#comment-4958</guid>
		<description>Sorry don&#039;t know why but the code is not pasting correctly try again.....//

function check_ip_address($ip_address) {
$octets = explode(&#039;.&#039;,$ip_address);
if (($octets[0] &gt; 0 &amp;&amp; $octets[0]  0 &amp;&amp; $octets[1]  0 &amp;&amp; $octets[2]  0 &amp;&amp; $octets[3] &lt; 255) &amp;&amp; (count($octets) == 4))
{ return TRUE; }
}</description>
		<content:encoded><![CDATA[<p>Sorry don&#8217;t know why but the code is not pasting correctly try again&#8230;..//</p>
<p>function check_ip_address($ip_address) {<br />
$octets = explode(&#8216;.&#8217;,$ip_address);<br />
if (($octets[0] &gt; 0 &amp;&amp; $octets[0]  0 &amp;&amp; $octets[1]  0 &amp;&amp; $octets[2]  0 &amp;&amp; $octets[3] &lt; 255) &amp;&amp; (count($octets) == 4))<br />
{ return TRUE; }<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: john</title>
		<link>http://roshanbh.com.np/2008/04/ip-address-validation-php.html/comment-page-1#comment-4957</link>
		<dc:creator>john</dc:creator>
		<pubDate>Fri, 18 Dec 2009 11:13:17 +0000</pubDate>
		<guid isPermaLink="false">http://roshanbh.com.np/2008/04/ip-address-validation-php.html#comment-4957</guid>
		<description>If you are checking for a valid IP address the first octet should be less than 224 - above this are reserved for multicast addresses. You may also want to check for broadcast addresses but this woupld require a lot more testing based on the Class of IP address. You may also want to check for RFC 1918 private addresses and well as 127.x.x.x looopback. I do not think regular expressions are they way to do this and it will require a proper php function. Here is my basic function just checking for a valid unicast IP address....

function check_ip_address($ip_address) {

	$octets = explode(&#039;.&#039;,$ip_address);
	
	if (($octets[0] &gt; 0 &amp;&amp; $octets[0]  0 &amp;&amp; $octets[1]  0 &amp;&amp; $octets[2]  0 &amp;&amp; $octets[3] &lt; 255) &amp;&amp;
		(count($octets) == 4))
		
		{ return TRUE; }

}</description>
		<content:encoded><![CDATA[<p>If you are checking for a valid IP address the first octet should be less than 224 &#8211; above this are reserved for multicast addresses. You may also want to check for broadcast addresses but this woupld require a lot more testing based on the Class of IP address. You may also want to check for RFC 1918 private addresses and well as 127.x.x.x looopback. I do not think regular expressions are they way to do this and it will require a proper php function. Here is my basic function just checking for a valid unicast IP address&#8230;.</p>
<p>function check_ip_address($ip_address) {</p>
<p>	$octets = explode(&#8216;.&#8217;,$ip_address);</p>
<p>	if (($octets[0] &gt; 0 &amp;&amp; $octets[0]  0 &amp;&amp; $octets[1]  0 &amp;&amp; $octets[2]  0 &amp;&amp; $octets[3] &lt; 255) &amp;&amp;<br />
		(count($octets) == 4))</p>
<p>		{ return TRUE; }</p>
<p>}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Juanra</title>
		<link>http://roshanbh.com.np/2008/04/ip-address-validation-php.html/comment-page-1#comment-4414</link>
		<dc:creator>Juanra</dc:creator>
		<pubDate>Wed, 19 Aug 2009 17:44:23 +0000</pubDate>
		<guid isPermaLink="false">http://roshanbh.com.np/2008/04/ip-address-validation-php.html#comment-4414</guid>
		<description>Another way to do this:

function validateIpAddress($ip_addr) {
    $long = ip2long($ip_addr);
    return !($long == -1 &#124;&#124; $long === FALSE);
}</description>
		<content:encoded><![CDATA[<p>Another way to do this:</p>
<p>function validateIpAddress($ip_addr) {<br />
    $long = ip2long($ip_addr);<br />
    return !($long == -1 || $long === FALSE);<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roshan</title>
		<link>http://roshanbh.com.np/2008/04/ip-address-validation-php.html/comment-page-1#comment-1752</link>
		<dc:creator>Roshan</dc:creator>
		<pubDate>Fri, 08 Aug 2008 15:57:28 +0000</pubDate>
		<guid isPermaLink="false">http://roshanbh.com.np/2008/04/ip-address-validation-php.html#comment-1752</guid>
		<description>Hi Decon...thanks for sharing that link...</description>
		<content:encoded><![CDATA[<p>Hi Decon&#8230;thanks for sharing that link&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Decon</title>
		<link>http://roshanbh.com.np/2008/04/ip-address-validation-php.html/comment-page-1#comment-1750</link>
		<dc:creator>Decon</dc:creator>
		<pubDate>Fri, 08 Aug 2008 13:18:13 +0000</pubDate>
		<guid isPermaLink="false">http://roshanbh.com.np/2008/04/ip-address-validation-php.html#comment-1750</guid>
		<description>You might find this URL useful (and faster without using reg-ex)

http://www.jimgrill.com/pages/content/validateip</description>
		<content:encoded><![CDATA[<p>You might find this URL useful (and faster without using reg-ex)</p>
<p><a href="http://www.jimgrill.com/pages/content/validateip" rel="nofollow">http://www.jimgrill.com/pages/content/validateip</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brian Szymanski</title>
		<link>http://roshanbh.com.np/2008/04/ip-address-validation-php.html/comment-page-1#comment-1289</link>
		<dc:creator>Brian Szymanski</dc:creator>
		<pubDate>Wed, 25 Jun 2008 17:27:09 +0000</pubDate>
		<guid isPermaLink="false">http://roshanbh.com.np/2008/04/ip-address-validation-php.html#comment-1289</guid>
		<description>Or you could do the whole kit+kaboodle in one regexp like so:

return preg_match(&quot;/^((\d{1,2}&#124;[01]\d{2}&#124;2([0-4]\d&#124;5[0-5]))\.){3}(\d{1,2}&#124;[01]\d{2}&#124;2([0-4]\d&#124;5[0-5]))$/&quot;,$ip_addr))</description>
		<content:encoded><![CDATA[<p>Or you could do the whole kit+kaboodle in one regexp like so:</p>
<p>return preg_match(&#8220;/^((\d{1,2}|[01]\d{2}|2([0-4]\d|5[0-5]))\.){3}(\d{1,2}|[01]\d{2}|2([0-4]\d|5[0-5]))$/&#8221;,$ip_addr))</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Roshan</title>
		<link>http://roshanbh.com.np/2008/04/ip-address-validation-php.html/comment-page-1#comment-717</link>
		<dc:creator>Roshan</dc:creator>
		<pubDate>Fri, 25 Apr 2008 15:47:39 +0000</pubDate>
		<guid isPermaLink="false">http://roshanbh.com.np/2008/04/ip-address-validation-php.html#comment-717</guid>
		<description>It won&#039;t work...try it...it will just validate a number like 0,1,2 or 5 only since it is equivalent to character set [0125]</description>
		<content:encoded><![CDATA[<p>It won&#8217;t work&#8230;try it&#8230;it will just validate a number like 0,1,2 or 5 only since it is equivalent to character set [0125]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: CC</title>
		<link>http://roshanbh.com.np/2008/04/ip-address-validation-php.html/comment-page-1#comment-716</link>
		<dc:creator>CC</dc:creator>
		<pubDate>Fri, 25 Apr 2008 13:51:42 +0000</pubDate>
		<guid isPermaLink="false">http://roshanbh.com.np/2008/04/ip-address-validation-php.html#comment-716</guid>
		<description>can you not simply use a regexp of: -

^[0-255]\.[0-255]\.[0-255]\.[0-255]$

i.e. four integers in the range of 0 to 255 with a period separating them?</description>
		<content:encoded><![CDATA[<p>can you not simply use a regexp of: -</p>
<p>^[0-255]\.[0-255]\.[0-255]\.[0-255]$</p>
<p>i.e. four integers in the range of 0 to 255 with a period separating them?</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 2/16 queries in 0.207 seconds using disk: basic
Object Caching 363/363 objects using disk: basic

Served from: roshanbh.com.np @ 2012-05-17 06:50:16 -->
