|
@@ -7,10 +7,12 @@ class ValidateUtil {
|
|
|
private val regexIP: Regex by lazyOf(Regex("^(?:(?: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]?)\$"))
|
|
|
private val regexPositiveInt: Regex by lazyOf(Regex("^[1-9]\\d*$"))
|
|
|
private val regexUrl: Regex by lazyOf(Regex("^(https?|ftp|file)://([\\da-z.-]+)\\.([a-z.]{2,6})([/\\w .-]*)*/?\$"))
|
|
|
+ private val regexIPHost: Regex by lazyOf(Regex("^(https?|ftp|file)://(?:(?: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]?)\$"))
|
|
|
|
|
|
fun isIP(ip: String): Boolean = regexIP.matches(ip)
|
|
|
fun isPositiveInt(num: String): Boolean = regexPositiveInt.matches(num)
|
|
|
fun isUrl(url: String): Boolean = regexUrl.matches(url)
|
|
|
+ fun isIPHost(url: String): Boolean = regexIPHost.matches(url)
|
|
|
fun isPort(port: String): Boolean = isPositiveInt(port) && port.toInt() < 65535
|
|
|
}
|
|
|
}
|