RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Accurate IP address verification
Expression
((0|1[0-9]{0,2}|2[0-9]?|2[0-4][0-9]|25[0-5]|[3-9][0-9]?)\.){3}(0|1[0-9]{0,2}|2[0-9]?|2[0-4][0-9]|25[0-5]|[3-9][0-9]?)
Description
Accurate IP address verification... Each numeric part of an IP address must be between 0 and 255. All patterns I have seen on the net cover this range but they allow leading zeros. The valid cases are: * 0 * 1, 10-19 and 100-199 aka 1[0-9]{0,2} * 2 and 20-29 aka 2[0-9]? * 200-249 aka 2[0-4][0-9] * 250-255 aka 25[0-5] * 3-9 and 30-99 aka [3-9][0-9]?
Matches
10.0.0.0 | 195.167.1.119 | 255.255.255.255
Non-Matches
010.0.0.0 | 195.167.01.119 | 256.20.55.23
Author Rating: The rating for this expression. Vassilis Petroulias
Source
Your Rating
Bad Good

Enter New Comment

Title
 
Name
 
Comment
 
Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Allows invalid IP addresses
Name: Dan R
Date: 2/24/2010 12:59:09 PM
Comment:
Allows 0.1.1.1 and 1.0.0.0. While 1.1.0.0 may be a valid IP (depending on mask) 1.0.0.0 will never be valid, nor would 0.1.1.1.


Title: General concept for long version patterns
Name: Vassilis Petroulias
Date: 12/30/2005 4:46:04 AM
Comment:
Thank you for your comment. In general I use long version and syntax when I distribute patterns while this way regex newbies can easily visualize the logic of a pattern. On the other hand experience developers can short them at dead time.


Title: A shorter version
Name: Jesse Houwing
Date: 12/29/2005 7:13:45 PM
Comment:
This does the same, but is a little shorter. I personally find it easier to read (though the part covering 0-99 is arguably harder). ^(([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])[.]){3}([1-9]?[0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$


Copyright © 2001-2014, RegexAdvice.com | ASP.NET Tutorials