I'd like to make my text field resign first responder after the cents are entered in a text field for entering currency. I'm using UIKeyboardTypeDecimalPad
so only numerals are entered. When the second numeral after the decimal point is entered I want the text field to resign first responder.
1
12
123
123.4
123.45 now resign first responder.
Do I have the delegate compare the text to the regular expression *\...
for each textDidChange
notification? Starting counting when .
is entered?
Is there a way to apply NSNumberFormatter
and setMaximumFractionDigits:2
to the text input field?
I believe it would be a bad user experience if you dismissed the keyboard after 2 digits from the decimal place. (Also wouldn't work for fraction-less currencies, such as Yen).
To dismiss a keyboard like this, the easiest option would be to dismiss the keyboard when the user touches outside of the keyboard area. You could do this by applying a `UITapGestureRecognizer' on the view just behind the keyboard when bringing it up, then removing it once the keyboard is dismissed.