Skip to content

Instantly share code, notes, and snippets.

@nileshpunjabi
Created October 31, 2014 06:03
Show Gist options
  • Save nileshpunjabi/19f6d029db6492717b4a to your computer and use it in GitHub Desktop.
Save nileshpunjabi/19f6d029db6492717b4a to your computer and use it in GitHub Desktop.
Textfield input limit by character set
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789+-"] invertedSet];
NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
return [string isEqualToString:filtered];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment