验证手机号,邮箱,车牌号是否合法
【摘要】 - (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view. NSLog(@"------%d------",[self isValidateEmail:@"12345"]); NSLog(@"------%d------",[self ...
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(@"------%d------",[self isValidateEmail:@"12345"]);
NSLog(@"------%d------",[self isValidateMobile:@"12345"]);
NSLog(@"---%d---------",[self isValidateCar:@"12345"]);
}
#pragma -mark -邮箱验证
-(BOOL)isValidateEmail:(NSString *)email
{
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailTest evaluateWithObject:email];
}
#pragma -mark -手机号码验证
-(BOOL) isValidateMobile:(NSString *)mobile
{
//手机号以13, 15,18开头,八个 \d 数字字符
NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
// NSLog(@"phoneTest is %@",phoneTest);
return [phoneTest evaluateWithObject:mobile];
}
#pragma -mark -车牌号验证
-(BOOL)isValidateCar:(NSString *)car
{
NSString *carRegex = @"^[A-Za-z]{1}[A-Za-z_0-9]{5}$";
NSPredicate *carTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",carRegex];
NSLog(@"carTest is %@",carTest);
return [carTest evaluateWithObject:car];
}
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)