入力した数値を次のように numberFormatter で確認します。
NSNumber * myNumber = [numberFormatter numberFromString:yourTextField.text];
if(myNumber)
//valid entered number
else
//invalid entered number
これには、UITextField のデリゲート メソッドを使用する必要があります。
- (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSNumberFormatter *numberFormatter = [NSNumberFormatter alloc]init]
[numberFormatter setNumberStyle:NSNumberFormatterNoStyle];
[numberFormatter setMaximumIntegerDigits:5];
[numberFormatter setMaximumFractionDigits:1];
NSNumber * myNumber = [numberFormatter numberFromString:string];
[numberFormatter release];
if(myNumber)
return YES;
else
return NO;
}