I have a calculator app in which I have a textfield in which if I enter any number; then it works fine. If I do not enter a number then it shows alert. I also want the user to be able to enter 1.5 but when I do this it shows alert “enter a number please”
So how can I enter decimal number? I am using the following code :
NSCharacterSet * set = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789"] invertedSet];
NSString*string=costToClientTextField.text;
if ([string rangeOfCharacterFromSet:set].location != NSNotFound) {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"Only a number can be entered into this input field " delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
costToClientTextField.text=@"";
}
Add the “.” in your set, like so