#import
@interfaceUtils : NSObject
#pragma 正则匹配手机号
+ (BOOL)checkTelNumber:(NSString*) telNumber;
#pragma 正则匹配用户密码6-18位数字和字母组合
+ (BOOL)checkPassword:(NSString*) password;
#pragma 正则匹配用户姓名,20位的中文或英文
+ (BOOL)checkUserName : (NSString*) userName;
#pragma 正则匹配用户身份证号
+ (BOOL)checkUserIdCard: (NSString*) idCard;
#pragma 正则匹员工号,12位的数字
+ (BOOL)checkEmployeeNumber : (NSString*) number;
#pragma 正则匹配URL
+ (BOOL)checkURL : (NSString*) url;
@end
#import "Utils.h"
@implementationUtils
#pragma 正则匹配手机号
+ (BOOL)checkTelNumber:(NSString*) telNumber
{
NSString*pattern =@"^1+[3578]+\d{9}";
NSPredicate*pred = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@",pattern];
BOOLisMatch = [predevaluateWithObject:telNumber];
returnisMatch;
}
#pragma 正则匹配用户密码6-18位数字和字母组合
+ (BOOL)checkPassword:(NSString*) password
{
NSString*pattern =@"^(?![0-9]+$)(?![a-zA-Z]+$)[a-zA-Z0-9]{6,18}";
NSPredicate*pred = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@",pattern];
BOOLisMatch = [predevaluateWithObject:password];
returnisMatch;
}
#pragma 正则匹配用户姓名,20位的中文或英文
+ (BOOL)checkUserName : (NSString*) userName
{
NSString*pattern =@"^[a-zA-Zu4E00-u9FA5]{1,20}";
NSPredicate*pred = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@",pattern];
BOOLisMatch = [predevaluateWithObject:userName];
returnisMatch;
}
#pragma 正则匹配用户身份证号15或18位
+ (BOOL)checkUserIdCard: (NSString*) idCard
{
NSString*pattern =@"(^[0-9]{15}$)|([0-9]{17}([0-9]|X)$)";
NSPredicate*pred = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@",pattern];
BOOLisMatch = [predevaluateWithObject:idCard];
returnisMatch;
}
#pragma 正则匹员工号,12位的数字
+ (BOOL)checkEmployeeNumber : (NSString*) number
{
NSString*pattern =@"^[0-9]{12}";
NSPredicate*pred = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@",pattern];
BOOLisMatch = [predevaluateWithObject:number];
returnisMatch;
}
#pragma 正则匹配URL
+ (BOOL)checkURL : (NSString*) url
{
NSString*pattern =@"^[0-9A-Za-z]{1,50}";
NSPredicate*pred = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@",pattern];
BOOLisMatch = [predevaluateWithObject:url];
returnisMatch;
}
@end