Verify that NSString contains the letters and numbers

advertisements

I'm looking for the best way to check that an NSString contains both numerical and alphabetical characters. What I have come up with so far is the code below but this just tells me that no characters were entered which aren't numbers or letters.

if( [[myNSString stringByTrimmingCharactersInSet:
            [NSCharacterSet alphanumericCharacterSet]] isEqualToString:@""]){
  //The string only contains alpha or numerical characters.
  //But now I want to check that both character sets are present ?
}


Just trim letterCharacterSet and decimalDigitCharacterSet and check if produced string is not equal to the original string:

if (![[myOriginalString stringByTrimmingCharactersInSet:[NSCharacterSet decimalDigitCharacterSet]] isEqualToString:myOriginalString]
     && ![[myOriginalString stringByTrimmingCharactersInSet:[NSCharacterSet letterCharacterSet]] isEqualToString:myOriginalString]) {
...
}