package sh.sar.basedbank.util object AccountInputParser { enum class InputType { MIB_ACCOUNT, // 17 digits starting with 9 BML_ACCOUNT, // 13 digits starting with 7 PHONE, // 7 digits starting with 7 or 9 NATIONAL_ID, // A followed by 6 digits EMAIL, UNKNOWN } /** * Strip spaces and remove a 960/+960 country code prefix, but only when * the stripped result is exactly 7 digits (so "9603456" is left intact). */ fun normalize(input: String): String { var s = input.replace(" ", "") val stripped = when { s.startsWith("+960") -> s.removePrefix("+960") s.startsWith("960") -> s.removePrefix("960") else -> null } if (stripped != null && stripped.matches(Regex("^\\d{7}$"))) s = stripped return s } fun detect(input: String): InputType { val s = input.trim() return when { s.matches(Regex("^9\\d{16}$")) -> InputType.MIB_ACCOUNT s.matches(Regex("^7\\d{12}$")) -> InputType.BML_ACCOUNT s.matches(Regex("^[79]\\d{6}$")) -> InputType.PHONE s.matches(Regex("^[Aa]\\d{6}$")) -> InputType.NATIONAL_ID s.contains("@") -> InputType.EMAIL else -> InputType.UNKNOWN } } }