I am using Xcode 14 Swift 5 and I am new to it. I am trying to make the textField accpet maximum 3 digits but also can have a decimal number in it with 2 digits. (E.g. the user can enter 123 or 123.45 but not 12345 nor 12134.54)
Thanks in advance.
here is my code to restrict the textField to accept max 3 digits but I can't write the rest.
// TextField Config
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
guard let text = textField.text else { return true }
let text_Length = text.count + string.count - range.length
if text_Length > 3 {
return false
}
return true
}
// Done