Sha256: b4d168918482e4d6db66a7f310c09aa1a1a5a390339f27b07a47a94905e63c90

Contents?: true

Size: 568 Bytes

Versions: 67

Compression:

Stored size: 568 Bytes

Contents

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

    val number = validationRegex.matchEntire(cleanedNumber)?.groupValues?.last() ?: throw IllegalArgumentException()
    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

67 entries across 67 versions & 1 rubygems

Version Path
trackler-2.2.1.12 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.2.1.11 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.2.1.10 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.2.1.9 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.2.1.8 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.2.1.7 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.2.1.6 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.2.1.5 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.2.1.4 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.2.1.3 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.2.1.2 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.2.1.1 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.2.1.0 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.2.0.6 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.2.0.5 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.2.0.4 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.2.0.3 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.2.0.2 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.2.0.1 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt
trackler-2.2.0.0 tracks/kotlin/exercises/phone-number/src/example/kotlin/PhoneNumber.kt