Skip to content

Commit

Permalink
Fix issue with clearing phone numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
3lvis committed Jun 14, 2024
1 parent 94a715a commit bcd945e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public struct EuropeanPhoneNumberInputValidator: InputValidatable {
}

private func validatePartialEuropeanPhoneNumber(_ phoneNumber: String) -> Bool {
guard !phoneNumber.isEmpty else { return true }

// Allow a single "+" as valid partial input
if phoneNumber == "+" {
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public struct NorwegianPhoneNumberInputValidator: InputValidatable {
}

private func validatePartialNorwegianPhoneNumber(_ phoneNumber: String) -> Bool {
guard !phoneNumber.isEmpty else { return true }

if phoneNumber.count == 8 {
return validateNorwegianPhoneNumber(phoneNumber)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class MixedPhoneNumberInputValidatorTests: XCTestCase {
XCTAssertFalse(validator.validateReplacementString("+4479111234567890123456", fullString: "", inRange: NSRange(location: 0, length: 0))) // Too long

// Test partial valid sequences
XCTAssertTrue(validator.validateReplacementString("", fullString: "+", inRange: NSRange(location: 0, length: 1))) // Was + to become empty
XCTAssertTrue(validator.validateReplacementString("+", fullString: "", inRange: NSRange(location: 0, length: 0)))
XCTAssertTrue(validator.validateReplacementString("4", fullString: "+", inRange: NSRange(location: 1, length: 0)))
XCTAssertTrue(validator.validateReplacementString("4", fullString: "+4", inRange: NSRange(location: 2, length: 0)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class NorwegianPhoneNumberInputValidatorTests: XCTestCase {
XCTAssertFalse(validator.validateReplacementString("123456789", fullString: "", inRange: NSRange(location: 0, length: 0))) // Too long

// Test partial valid sequences
XCTAssertTrue(validator.validateReplacementString("", fullString: "2", inRange: NSRange(location: 0, length: 1))) // Was 2 to become empty
XCTAssertTrue(validator.validateReplacementString("4", fullString: "", inRange: NSRange(location: 0, length: 0))) // Starts with 4
XCTAssertTrue(validator.validateReplacementString("2", fullString: "", inRange: NSRange(location: 0, length: 0))) // Starts with 2
XCTAssertTrue(validator.validateReplacementString("9", fullString: "", inRange: NSRange(location: 0, length: 0))) // Starts with 9
Expand Down

0 comments on commit bcd945e

Please sign in to comment.