密码输入框-密码限制:字母,数字,下划线

// 数字和字母
#define ALPHANUM @ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_"


#pragma mark - UITextFieldDelegate
- ( BOOL )textField:( UITextField *)textField shouldChangeCharactersInRange:( NSRange )range replacementString:( NSString *)string
{
   
NSCharacterSet *cs = [[ NSCharacterSet characterSetWithCharactersInString : ALPHANUM ] invertedSet ];
   
NSString *filtered = [[string componentsSeparatedByCharactersInSet :cs] componentsJoinedByString : @"" ];
   
BOOL result = [string isEqualToString :filtered];
   
if (!result) {
        [
self showHUDInView : self . view justWithText : @" 密码只能输入数字、字母、下划线 " disMissAfterDelay : 2.0 ];
       
return result;
    }
   
return result;
}

你可能感兴趣的:(ios,UITextField,输入限制,密码输入框,密码限制)