         let text = self.text ?? ""
         let range = NSRange(location: 0, length: text.characters.count)
         guard let match = expirationRx.firstMatch(in: text, options: [], range: range), match.numberOfRanges >= 3 else {
-            selectedMonth = nil
-            selectedYear = nil
+            selectedMonth = 0
+            selectedYear = 0
             return
         }
         
         let monthText = textInRange(match.rangeAt(1))
         let yearText = textInRange(match.rangeAt(2))
-        selectedMonth = Int(monthText)
-        selectedYear = Int(yearText)?.advanced(by: 2000)
+        selectedMonth = Int(monthText) ?? 0
+        selectedYear = Int(yearText)?.advanced(by: 2000) ?? 0
     }
     
     private func textInRange(_ range: NSRange) -> String {

        
        return rx
    }()
  
    /// Currently selected month, `nil` if no month has been selected.
    public var selectedMonth: Int? = nil
    /// Currently selected year, `nil` if no year has been selected.
    public var selectedYear: Int? = nil
    
    /// Boolean indicating wether current input is valid or not.
    public override var isValid: Bool {

        let calendar = Calendar(identifier: Calendar.Identifier.gregorian)
        let thisMonth = calendar.component(.month, from: now)
        let thisYear = calendar.component(.year, from: now)
        guard self.selectedYear != 0, self.selectedMonth != 0 else {
            return false
        }
        
        if (self.selectedYear == thisYear) {
            return thisMonth <= self.selectedMonth
        } else {
            return thisYear < self.selectedYear
        }
    }
    
