Possible Duplicate:
Decimal point in UIKeyboardTypeDecimalPad can’t be used in mathematical calculation
I have an iPhone app where we are using the UIKeyboardTypeDecimalPad for input which has been working fine for us until we have started to localize the application, the problem we now face is that when the language is switched to French or German the decimal point on the keypad changes from a full stop (.
) to a comma (,
).
We are currently running this code to restrict the input of multiple decimal points i.e. 12.4.4 with this code it will only allow 12.4 to be entered
This works fine but now we also need to check for the comma and also convert the users input for our calculations if it has a comma
Is there a better way to restrict the input on the keypad for both comma and full stop?
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
NSString *currentText = textField.text;
if ([currentText rangeOfString:@"." options:NSBackwardsSearch].length == 0) {
return YES;
} else {
if ([string rangeOfString:@"." options:NSBackwardsSearch].length == 0) {
return YES;
} else {
return NO;
}
}
return NO;
}
Thanks Aaron