Hi,
I have been trying to figure out how to restrict a users input with NSTextField so that it only allows numeric input with a single decimal point however for the past few hours all my efforts have failed.
So far I have created a custom numberformatter and assigned it to the NSTextfield in interface builder and now I can restrict the length of the input and also what is allowed to be inputted by using the following:
This works fine however the user can input more than one decimal i.e. 12...23..22, I am unsure of how to restrict this, any help would be appreciated.
Thanks Aaron
I have been trying to figure out how to restrict a users input with NSTextField so that it only allows numeric input with a single decimal point however for the past few hours all my efforts have failed.
So far I have created a custom numberformatter and assigned it to the NSTextfield in interface builder and now I can restrict the length of the input and also what is allowed to be inputted by using the following:
Code:
-(bool)isPartialStringValid:(NSString *)partialString
newEditingString:(NSString**)newString
errorDescription:(NSString**)error
{
NSRange inRange;
NSCharacterSet *allowedChars = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789."] invertedSet];
inRange = [partialString rangeOfCharacterFromSet:allowedChars];
NSLog(@"Original String = %@", partialString);
if(inRange.location != NSNotFound)
{
NSLog(@"Name input contains disallowed character.");
NSBeep();
return NO;
}
*newString = partialString;
return YES;
}
This works fine however the user can input more than one decimal i.e. 12...23..22, I am unsure of how to restrict this, any help would be appreciated.
Thanks Aaron