The following is an extension method for a class that determines whether a string contains only NSString
letters, whether it contains only numbers, whether it contains only letters and numbers:
//Letters-(BOOL) cdm_isonlyletters {nscharacterset*lettercharacterset =[[Nscharacterset Lettercharacterset] invertedset]; return([Self rangeofcharacterfromset:lettercharacterset].location = =nsnotfound);}//Digital-(BOOL) cdm_isonlynumbers {nscharacterset*numset = [[Nscharacterset charactersetwithcharactersinstring:@"0123456789"] Invertedset]; return([Self rangeofcharacterfromset:numset].location = =nsnotfound);}//Letters and Numbers-(BOOL) cdm_isonlyalphanumeric {nscharacterset*numandlettercharset =[[Nscharacterset Alphanumericcharacterset] invertedset]; return([Self rangeofcharacterfromset:numandlettercharset].location = =nsnotfound);}
Effect Show:
iOS judgment letters, numbers strings