Skip to content

Instantly share code, notes, and snippets.

@pardel
Created February 21, 2017 15:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pardel/81eee1d308471fde2a5ccc4243372aad to your computer and use it in GitHub Desktop.
Save pardel/81eee1d308471fde2a5ccc4243372aad to your computer and use it in GitHub Desktop.
swift IPv4 validation
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