I have a NSTextField which should only accept numbers in a certain range say (-72000.00 to 72000.00).
I tried using NSFormatter whihc worked partially. when i hit any alphabet character on the keyboard, the value in the NSTextField stays numeric but the cursor moves forward which is not desired. Heres how i set the formatter. NSNumberFormatter* numFormatr = [[NSNumberFormatter alloc] init]; [numFormatr setFormatterBehavior:NSNumberFormatterBehaviorDefault]; [numFormatr setNumberStyle:NSNumberFormatterDecimalStyle]; [numFormatr setMinimumFractionDigits:2]; [mtextfield setFormatter:numFormatr]; Am i doing something wrong here..?? I tried an alternate approach using the delegate method controlTextDidChange: I ended up with the same problem as above. cursor position is incremented when an invalid character is typed. - (void) controlTextDidChange:(NSNotification *)obj { // get the string value from the textfield // eliminate invalid characters in the string // set the result string as stringvalue of textfield } I was wondering if there is any alternative / better approach for validating text in a textfield?? Thanks, Abhinay. _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com