Sha256: 74eaa4977087e56f292cc3da5b2f385bd910805933d4e896b035661b336078c0

Contents?: true

Size: 533 Bytes

Versions: 180

Compression:

Stored size: 533 Bytes

Contents

data class PhoneNumber(private val rawNumber: String) {
    companion object {
        private val validationRegex = Regex("^1?(\\d{10})$")
    }
    private val cleanedNumber = rawNumber.replace(Regex("[^\\d]"), "")

    val number = validationRegex.matchEntire(cleanedNumber)?.groupValues?.last() ?: "0000000000"
    val areaCode = number.substring(0, 3)
    val exchangeCode = number.substring(3, 6)
    val subscriberNumber = number.substring(6, 10)

    override fun toString() = "($areaCode) $exchangeCode-$subscriberNumber"
}

Version data entries

180 entries across 180 versions & 1 rubygems

Version Path
trackler-2.1.0.24 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.1.0.23 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.1.0.22 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.1.0.21 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.1.0.20 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.1.0.19 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.1.0.18 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.1.0.17 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.1.0.16 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.1.0.15 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.1.0.14 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.1.0.13 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.1.0.12 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.1.0.11 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.1.0.10 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.1.0.9 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.1.0.8 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.1.0.7 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.1.0.6 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.1.0.5 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt