美文网首页
iOS开发常用输入校验

iOS开发常用输入校验

作者: 呦嚯嚯嚯12138 | 来源:发表于2016-10-03 16:05 被阅读28次

    1、数字字符校验

    #define NUMBERSPERIOD @"0123456789."

    - (BOOL)CheckInput:(NSString *)string {

    NSCharacterSet *cs;

    cs = [[NSCharacterSet characterSetWithCharactersInString:NUMBERSPERIOD] invertedSet];

    NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];

    BOOL basicTest = [string isEqualToString:filtered];

    return basicTest;

    }

    2、判断用户名,在2-16位

    - (BOOL)CheckInput:(NSString *)text {

    NSString*Regex = @"^\\w{2,16}{1}";

    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELFMATCHES %@", Regex];

    return [emailTest evaluateWithObject:text];

    }

    3、判断手机号码,1开头的十一位数字

    - (BOOL)CheckInput:(NSString *)text {

    NSString *Regex = @"1\\d{10}";

    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELFMATCHES %@", Regex];

    return [emailTest evaluateWithObject:text];

    }

    4、判断邮箱

    - (BOOL)CheckInput:(NSString *)text {

    NSString *Regex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";

    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELFMATCHES %@", Regex];

    return [emailTest evaluateWithObject:text];

    }

    5、判断密码,6-16位

    - (BOOL)CheckInput:(NSString *)text

    {

    NSString *Regex = @"\\w{6,16}";

    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELFMATCHES %@", Regex];

    return [emailTest evaluateWithObject:text];

    }

    相关文章

      网友评论

          本文标题:iOS开发常用输入校验

          本文链接:https://www.haomeiwen.com/subject/rkkjyttx.html