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