1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// RegexUtil.m
// XFFruit
//
// Created by 陈俊俊 on 15/9/9.
// Copyright (c) 2015年 Xummer. All rights reserved.
//
#import "RegexUtil.h"
@implementation RegexUtil
+ (BOOL)isValidateNmuberAndFloat:(NSString *)candidate{
NSString *regStr=@"(^[0-9]+(\\.[0-9]+)?$)";
NSPredicate *numberTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regStr];
return [numberTest evaluateWithObject:candidate];
}
+ (BOOL)isValidatePhone:(NSString *) candidate {
// NSString *phoneRegex = @"(13[0-9]|15[0|3|6|7|8|9]|18[2|3|6|7|8|9])\\d{8}";
NSString *phoneRegex=@"(\\d{11,11})";
NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", phoneRegex];
return [phoneTest evaluateWithObject:candidate];
}
// 手机号前3位规定
+ (BOOL)isValidatePhoneNew:(NSString *)candidate {
// NSString *phoneRegex = @"(13[0-9]|15[0|3|6|7|8|9]|18[2|3|6|7|8|9])\\d{8}";
NSString *phoneRegex = @"(13[0-9]|14[0-9]|15[0-9]|18[0-9]|17[0|6|7|8])\\d{8}";
NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", phoneRegex];
return [phoneTest evaluateWithObject:candidate];
}
@end