public
Last active

Women Who Code iOS Study group Michele Titolo showed us how to check only for numbers in a UITextFIeld thanks for sponsoring us, SocialChorus!

  • Download Gist
ViewController.m
Objective-C
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#pragma mark -
#pragma mark - UITextFieldDelegate
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
// let's check if the string is range is a number
NSRange characterRange = [string rangeOfCharacterFromSet:[NSCharacterSet letterCharacterSet]];
// if we've detected a character in our string, we're not going to insert that letter character in our text field
if(characterRange.location != NSNotFound) {
return NO;
}
return YES;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.