package com.doverfuelingsolutions.issp.utils

class ValidateUtil {

    companion object {

        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 .-]*)*/?\$"))

        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 isPort(port: String): Boolean = isPositiveInt(port) && port.toInt() < 65535
    }
}