You are not Logged in
Would you like to Login or Register

Today is: 05 February 2012
Check this months hot topics

IP Address regular expression

string pattern = @"\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"
 
kick it on DotNetKicks.com del.icio.us digg Mister Wong YahooMyWeb Reddit Furl Spurl blogmarks
Paul Hayman Skype
Author : Paul Hayman
Published : 04 August 2006

Paul is the COO of kwiboo ltd consultant and has more than a decade of IT consultancy experience. He has consulted for a number of blue chip companies and has been exposed to the folowing sectors: Utilities, Telecommunications, Insurance, Media, Investment Banking, Leisure, Legal, CRM, Pharmaceuticals, Interactive Gaming, Mobile Communications, Online Services. Paul is the COO and co-founder of kwiboo (http://www.kwiboo.com/) and is also the creator of GeekZilla.

Comments

Shatheesh said:

Thanks... It works... :)

November 15, 2006 - 11:04 AM

kamal said:

Thanks for the Regex ..

Could you also include regular expression strings for other validations too,generally not found over net.

Thanks in advance!

July 05, 2007 - 8:11 AM

phayman said:

July 05, 2007 - 8:59 AM

Paul said:

It appears that the regex does not consider Ipv6

January 22, 2008 - 7:55 PM

masterik said:

I've found another one at http://www.regular-expressions.info/examples.html:

\b(?:(?: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]?)\b

March 14, 2008 - 10:30 AM

Wieland K said:

thank you! works great

May 20, 2008 - 11:37 PM

steve said:

Thanks. You saved me a lot of time and trouble!

July 11, 2008 - 1:22 PM

a++ said:

try this:

^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$

April 22, 2009 - 10:24 AM

immeëmosol said:

Wouldn't your expression allow for:

000.000.000.000 ?

I do this to check if I am on my home-server (PHP):

preg_match('/^127(?:\\.(?:25[0-5]|2[0-4][0-9]|1[0-9]{1,2}|[0-9]?)){2}\\.[1-9][0-9]{0,2}$/' , $SERVER['SERVERADDR'])

Regexes are good stuff.

May 06, 2009 - 12:53 PM

Haider said:

Thanks Great working...

July 16, 2009 - 7:36 AM

haidiva said:

HI , I want regular expre.. for ip address with wild card support .

Can any body help me on this .

September 03, 2010 - 6:59 AM

ffatheranderson said:

Hi i won't to fix the "zero" and "255" ending ip address allowing

Bellow the rgex that don't allow addresses like "x.x.x.255" or "x.x.x.0" it is good for IP address as is.

^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){2}(\.([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4]))$

And this regex (was sended by steve(thanx you very useful)) good for check network address or multicast addressing like x.x.x.255" or "x.x.x.0.

^([1-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])){3}$

April 26, 2011 - 5:20 PM

Add Comment

Enter your comment below and it will be submitted for moderation.

Your Name

Add Tag

Please enter tags for this article, seperated by semi-colon ;

View Tag's by : # articles | # views

More Publications

URL Regular Expression
Paul Hayman - 26/07/2006
IP Address regular expression
Paul Hayman - 04/08/2006
IsGuid() (Regular Expression Guid Match)
Paul Hayman - 14/06/2006
Date Regular Expression (dd/MMM/yyyy)
Paul Hayman - 26/10/2007
Hex code Regular Expression (#F0F0F0)
Paul Hayman - 12/10/2007