I want to limit the user input to only valid numbers and am using the following:
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
guard CharacterSet(charactersIn: " -0123456789.,\t\n").isSuperset(of: CharacterSet(charactersIn: text)) else {
return false
}
return true
}
But this does not prevent entering more than one decimal point such as "1.2.3". Is there a simple way to prevent that?