Thursday, August 26, 2010

How to validate IP address using Regular expression

string exp = @"
    ^(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]?)$";
string ipAddress = "127.0.0.1";
bool isMatch = Regex.IsMatch(ipAddress,exp);

3 comments:

Anonymous said...

Hi,
Please let me know the regular expression which validates IP address and excludes localhost

Thank you

Anonymous said...

Given regular expression works, I have a requirement to exclude local host. Please let me know how to do that

Pushpa said...

Given regular expression works. I have a requirement to exclude local host. Please let me know how to do that.

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...