HB
Мне это в модуль для react-native переводить, немного долго выходит. А так бы сразу увидел
Size: a a a
HB
K
HB
NZ
🕷
AO
🕷
DG
🕷
🕷
DG
var isPhoneNumberFormatValidPublisher:AnyPublisher<PhoneNumberCheckStatus,Never> {
$phoneNumber
.debounce(for: 0.05, scheduler: RunLoop.main)
.removeDuplicates()
.map {
self.phoneNumberCheck($0) }
.receive(on: RunLoop.main)
.eraseToAnyPublisher()
}
DG
func phoneNumberCheck (_ phone:String)->PhoneNumberCheckStatus {
var startingWithPlus =
false
var startingWith8 =
false
var startingWith9 =
false
let text = phone.replacingOccurrences(of: "", with: "", options: .numeric)
phoneNumber = phoneNumber.applyPatternOnNumbers(pattern: "+# (###) ###-##-##", replacmentCharacter: "#")
if text == "" {
return .empty}
if text.first == "+" { startingWithPlus =
true
}
if text.first == "8" { startingWith8 =
true
phoneNumber = "7\(phoneNumber.dropFirst().dropFirst())"
}
if text.first == "9" { startingWith9 =
true
phoneNumber = "+7(\(phoneNumber)"
}
if startingWith8 && text.count == 11 {
return .valid}
if startingWith9 && text.count == 10 {
return .valid}
if startingWithPlus && (text.replacingOccurrences(of: "+", with: "")).first != "7" {
print ("starting incorrect")
return .startingIncorrect
}
else {
if text.count != (startingWithPlus ? 18:17) {
print ("short")
return .short
}
else {
return .valid
}
}
}
DG
DG
DG
DG