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.52 tracks/kotlin/exercises/phone-number/.meta/src/reference/kotlin/PhoneNumber.kt
trackler-2.2.1.51 tracks/kotlin/exercises/phone-number/.meta/src/reference/kotlin/PhoneNumber.kt
trackler-2.2.1.50 tracks/kotlin/exercises/phone-number/.meta/src/reference/kotlin/PhoneNumber.kt
trackler-2.2.1.49 tracks/kotlin/exercises/phone-number/.meta/src/reference/kotlin/PhoneNumber.kt
trackler-2.2.1.48 tracks/kotlin/exercises/phone-number/.meta/src/reference/kotlin/PhoneNumber.kt
trackler-2.2.1.47 tracks/kotlin/exercises/phone-number/.meta/src/reference/kotlin/PhoneNumber.kt
trackler-2.2.1.46 tracks/kotlin/exercises/phone-number/.meta/src/reference/kotlin/PhoneNumber.kt
trackler-2.2.1.45 tracks/kotlin/exercises/phone-number/.meta/src/reference/kotlin/PhoneNumber.kt
trackler-2.2.1.44 tracks/kotlin/exercises/phone-number/.meta/src/reference/kotlin/PhoneNumber.kt
trackler-2.2.1.43 tracks/kotlin/exercises/phone-number/.meta/src/reference/kotlin/PhoneNumber.kt
trackler-2.2.1.42 tracks/kotlin/exercises/phone-number/.meta/src/reference/kotlin/PhoneNumber.kt
trackler-2.2.1.41 tracks/kotlin/exercises/phone-number/.meta/src/reference/kotlin/PhoneNumber.kt
trackler-2.2.1.40 tracks/kotlin/exercises/phone-number/.meta/src/reference/kotlin/PhoneNumber.kt
trackler-2.2.1.39 tracks/kotlin/exercises/phone-number/.meta/src/reference/kotlin/PhoneNumber.kt
trackler-2.2.1.38 tracks/kotlin/exercises/phone-number/.meta/src/reference/kotlin/PhoneNumber.kt
trackler-2.2.1.37 tracks/kotlin/exercises/phone-number/.meta/src/reference/kotlin/PhoneNumber.kt
trackler-2.2.1.36 tracks/kotlin/exercises/phone-number/.meta/src/reference/kotlin/PhoneNumber.kt
trackler-2.2.1.35 tracks/kotlin/exercises/phone-number/.meta/src/reference/kotlin/PhoneNumber.kt
trackler-2.2.1.34 tracks/kotlin/exercises/phone-number/.meta/src/reference/kotlin/PhoneNumber.kt
trackler-2.2.1.33 tracks/kotlin/exercises/phone-number/.meta/src/reference/kotlin/PhoneNumber.kt