Re: Validating form input w/o core data
Re: Validating form input w/o core data
- Subject: Re: Validating form input w/o core data
- From: Andre Masse <email@hidden>
- Date: Wed, 28 Sep 2011 17:04:43 -0400
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:email@hidden>
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 (email@hidden)
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:
This email sent to email@hidden