Create a gist now

Instantly share code, notes, and snippets.

Women Who Code iOS Study group Michele Titolo showed us how to check only for numbers in a UITextFIeld thanks for sponsoring us, SocialChorus!
#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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment