|
I have a Form with a Text Field for entering a dollar amount (401k Balance). Currently the user can enter as many digits to the right of the decimal place as they want. I would like to restrict their ability to enter numbers beyond the hundreth place (beyond two decimal places).
|
|
You could make the keyboard disappear as soon as the user has entered two decimal places. To do so, you would need to observe the vm.userData.startBalance401k value, convert it into a string and count the digits after the decimal point.
Add this after .keyboardType(.decimalPad):
|
|
As a possibility. This will allow you to enter maximum 2 digits after decimal place. Data is considered as Double... but maybe it is different in your model.
|
|
@ygeras, your
@comeandtakeit99, I would suggest trying a different approach. Some ideas:
But has the proviso that you have to have another
|
|
As a quick note with the TextField for label give the user chance to change the label directly if use
|
|
The label |
|
On Sodapool's suggestion, while that is a way to accomplish it, it will not (reliably, anyway) work if the number is pasted. I use NumberFormatter as roosterboy suggested. Note that one NumberFormatter instance can be reused over and over. |
|
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.