Last active
December 16, 2015 03:19
-
-
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!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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