判断字符串中包含数字或字母

目录

//是否是n位纯数字
-(BOOL)validateOfLength:(NSInteger)length WithString:(NSString *)str{
    /*
     @"^\\d{6}$"
     (6个连续数字,以数字开头,以数字结尾)
     */
    NSString *pwdRegex = [NSString stringWithFormat:@"^\\d{\%ld}$",(long)length];
    NSPredicate *pwdTest = [NSPredicate predicateWithFormat:@"SELF MATCHES \%@",pwdRegex];
    BOOL isMatch= [pwdTest evaluateWithObject:str];
    
    if (!isMatch) {
        return NO;
    }
    return isMatch;
}

打赏一个呗

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦