美文网首页
日期正则

日期正则

作者: 就用帅气点的昵称吧 | 来源:发表于2018-06-03 19:33 被阅读0次

#pragma 正则匹配手机号

+ (BOOL)checkTelNumber:(NSString*) telNumber

{

    NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9])|(17[0,0-9]))\\d{8}$";

    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];

    return[phoneTestevaluateWithObject:telNumber];

}

#pragma 正则匹配用户密码3-18位数字和字母组合

+ (BOOL)checkPassword:(NSString*) password

{

    NSString *pattern = @"^[A-Za-z0-9]{6,18}$";//@"^(?![0-9]+$)(?![a-zA-Z]+$)[a-zA-Z0-9]{3,18}";

    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];

    BOOLisMatch = [predevaluateWithObject:password];

    returnisMatch;

}

#pragma 日期正则 YYYY-MM-DD

+ (BOOL)checkDate:(NSString*) date

{

    NSString *pattern = @"(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)";//@"^(?![0-9]+$)(?![a-zA-Z]+$)[a-zA-Z0-9]{3,18}";

    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];

    BOOLisMatch = [predevaluateWithObject:date];

    returnisMatch;

}

#pragma 正则匹配网址

+ (BOOL)checkUrlString:(NSString*) urlString

{

    NSString *pattern = @"((http[s]{0,1}|ftp)://[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)|(www.[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)";

    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];

    BOOLisMatch = [predevaluateWithObject:urlString];

    returnisMatch;

}

相关文章

网友评论

      本文标题:日期正则

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