Skip to content

Instantly share code, notes, and snippets.

@romyilano
Last active December 16, 2015 03:19
Show Gist options
  • Select an option

  • Save romyilano/5368849 to your computer and use it in GitHub Desktop.

Select an option

Save romyilano/5368849 to your computer and use it in GitHub Desktop.
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