Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 0.52 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. how to validate a string whether its alphanumeric or number
  2. NSString *string = myTextField.text;
  3. NSCharacterSet *alphanumericSet = [NSCharacterSet alphanumericCharacterSet];
  4. NSCharacterSet *numberSet = [NSCharacterSet decimalDigitCharacterSet];
  5. BOOL isAplhaNumericOnly= [[string stringByTrimmingCharactersInSet:alphanumericSet] isEqualToString:@""] && ![[string stringByTrimmingCharactersInSet:numberSet] isEqualToString:@""];
  6.        
  7. NSLog(@"isAplhaNumericOnly: %d",isAplhaNumericOnly);
  8.        
  9. if(isAplhaNumericOnly) {
  10.     return;
  11. }