Hi all.
I'm developing a savings goal app, and there is a screen that allows users to input data about a new goal.
I want to make sure that the user cannot input 2 decimal points on the saving amount text field otherwise the app will crash.
Does anybody have a solution to this?
Here's my code:
@IBAction func createSaving(_ sender: Any) {
if(savingTitleTxt.text!.isEmpty){
self.view.makeToast("Error. Please specify title.", duration: 2.0, position: .bottom)
return
}
if(savingAmountTxt.text!.isEmpty || savingAmountTxt.text!.contains(" ")){
self.view.makeToast("Error. Please specify a valid goal amount.", duration: 2.0, position: .bottom)
return
}
var tempList:[SavingItem] = getData()
tempList.append(SavingItem(title: savingTitleTxt!.text!, image: savingImage!.image!.pngData()!, goal: Double(savingAmountTxt!.text!)!, saved: 0))
saveData(list: tempList)
self.view.makeToast("Success", duration: 2.0, position: .bottom)