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.

Azure Storage Account Types

Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...