fun isValidIPAddress(address: String?): Boolean { var address = address if (address == null || address.length == 0) { return false } var ipv6Expected = false if (address[0] == '[') { if (address.length > 2 && address[address.length - 1] == ']') { address = address.substring(1, address.length - 1) ipv6Expected = true } else { return false } } if (address[0].digitToIntOrNull(16) ?: -1 != -1 || address[0] == ':') { var addr: ByteArray? = null addr = strToIPv4(address) if (addr == null) { addr = strToIPv6(address) } else if (ipv6Expected) { return false } if (addr != null) { return true } } return false }
Checks whether < tt > address < /tt > is a valid IP address string .