Hi - I have been trying to write a script that limits textfield entries to numeric values only and to a maximum of five. I tried using NSCharacterSet’s characterSetWithCharactersInString_(“0123456789”) and then looping through the textfield’s strings, but id did not work. I then thought of getting notifications from the textfield and getting the numeric values using currentEditor() and then textStorage()'s string(), since to my understanding that a textfield is nothing but an NSTextView, but i am unable to put any meaningful code to get any results.
Could someone assist me in writing the code please.
How about you just add a number formatter on the field? You can’t tab out if the entry isn’t a number. Not sure how you deal with using a button if there are no other fields to enter.
I did use an NSNumberFormatter, but it still lets me enter strings other that numerics. I failed to mention in my post that I an also trying to get the process to stop as soon as a non-numeric value was entered.
I did find controlTextDidEndEditing method from NSControl which has NSNotifications as a parameter.