You can use formatters for this too. Here's the code I'm using (modify
the characters you need to allow in addCharactersInString:).
// allow only digits and +-*/.
- (BOOL)isPartialStringValid:(NSString **)partialStringPtr
proposedSelectedRange:(NSRangePointer)proposedSelRangePtr
originalString:(NSString *)origString
originalSelectedRange:(NSRange)origSelRange
errorDescription:(NSString **)error
{
NSMutableCharacterSet *alphaNums = [NSMutableCharacterSet
decimalDigitCharacterSet];
[alphaNums addCharactersInString:@"+-*/."];
NSCharacterSet *inStringSet = [NSCharacterSet
characterSetWithCharactersInString:*partialStringPtr];
if ([alphaNums isSupersetOfSet:inStringSet]) {
return YES;
}
return NO;
}
Cheers,
Andre Masse
------------------------------------------------------------------------
Graham Cox <mailto:graham....@bigpond.com>
September 28, 2011 03:02
To prevent characters from being entered as they're typed, you'll also
want to use the field editor's delegate methods to reject unwanted
characters (formatters only validate after the entry is submitted).
_______________________________________________
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