Created
April 14, 2012 20:05
-
-
Save gr4y/2387672 to your computer and use it in GitHub Desktop.
allow only numbers in UITextField. For now without currency!
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
| - (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string | |
| { | |
| NSCharacterSet *nonNumberSet = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789."] invertedSet]; | |
| BOOL result = NO; | |
| if([string length] == 0){ //backspace | |
| result = YES; | |
| } | |
| else{ | |
| if([string stringByTrimmingCharactersInSet:nonNumberSet].length > 0){ | |
| result = YES; | |
| } | |
| } | |
| return result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Only works with US numbers tho.