I am trying to do a text field for credit card expiry date and using following code.
if range.length > 0 {
return true
}
if string == "" {
return false
}
if range.location > 6 {
return false
}
var originalText = textField.text
let replacementText = string.replacingOccurrences(of: " ", with: "")
if !CharacterSet.decimalDigits.isSuperset(of: CharacterSet(charactersIn: replacementText)) {
return false
}
if range.location == 4 {
originalText?.append("/")
textField.text = originalText
}
return true
However, using that code user can write 5145/52 which is not normal for expiry date. How can I limit year between i.e. 2000 to 2018 and month values 01 to 12?