Created
February 21, 2017 15:19
-
-
Save pardel/81eee1d308471fde2a5ccc4243372aad to your computer and use it in GitHub Desktop.
swift IPv4 validation
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
func isValidIPv4(_ ip: String) -> Bool { | |
return ip | |
.characters.split(separator: ".").map { String($0) } | |
.flatMap { Int($0) } | |
.filter { (0...255).contains($0) } | |
.count == 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment