Created
May 19, 2023 18:29
-
-
Save wchesley/8787322e4637c8e1548973713c7f230d to your computer and use it in GitHub Desktop.
Validate IPv4 Address C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Tests string to see if it is valid IPv4 address | |
/// </summary> | |
/// <param name="ip">String to test</param> | |
/// <returns>True if string is IP address, False otherwise</returns> | |
private bool ValidateIpv4Address(string ip) | |
{ | |
IPAddress address; | |
return ip != null && ip.Count(c => c == '.') == 3 && | |
IPAddress.TryParse(ip, out address); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment