From 498cb26ebe63d9882bf113835a9d843992fa5ba6 Mon Sep 17 00:00:00 2001 From: Ahmed Fitoh Date: Mon, 26 Oct 2020 14:43:12 +0200 Subject: [PATCH] - Check for custom keyboards in case of numeric otp input. --- OTPFieldView/OTPFieldView.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/OTPFieldView/OTPFieldView.swift b/OTPFieldView/OTPFieldView.swift index bcee25d..233dc02 100644 --- a/OTPFieldView/OTPFieldView.swift +++ b/OTPFieldView/OTPFieldView.swift @@ -259,6 +259,11 @@ extension OTPFieldView: UITextFieldDelegate { public func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { let replacedText = (textField.text as NSString?)?.replacingCharacters(in: range, with: string) ?? "" + // Check for custom keyboards in case of numeric otp input. + if otpInputType == .numeric && replacedText.rangeOfCharacter(from: CharacterSet.decimalDigits.inverted) != nil { + return false + } + // Check since only alphabet keyboard is not available in iOS if !replacedText.isEmpty && otpInputType == .alphabet && replacedText.rangeOfCharacter(from: .letters) == nil { return false