dotnet-Snippets.com
Snippets: 61 | Registered User: 61 | Visitors online: 8
Main Menu

Home
Random Snippet
FAQs
Contact Us
Imprint
RSS Feeds

Rss All languages
Rss C#
Rss VB.NET
Rss C++
Rss J#
Rss ASP.NET
Google Ads

Sri Lanka .NET 
                Forum Member
Determines whether the specified string is an IP address

Author: Jan Welker
Programming Language: C# Rating:
not yet rated

Views: 2372

Description:

Determines whether the specified string is an IP address using Regex.

Example:

"0.0.0.0" bis "255.255.255.255" valid
"1.2.3.256" oder "0.0.2" invalid




C#
1
2
3
4
5
6
7
8
9
10
11
/// <summary>
/// Determines whether the specified string is an IP address.
/// </summary>
/// <param name="IP">The string.</param>
/// <returns>
/// 	<c>true</c> if the specified IP is IP; otherwise, <c>false</c>.
/// </returns>
private bool IsIP(string IP)
{
    return System.Text.RegularExpressions.Regex.IsMatch(IP, @"\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");
}


Poor Excellent
1 2 3 4 5 6 7 8 9 10
Sign in to vote for this snippet.

Comments:
(Please log in to wrtite an comment.)