Add NSString Categories
1. In Nsstring+check.h, add the method;
-(BOOL) checkphonenuminput;
2. In the nsstring+check.m file;
-(BOOL) checkphonenuminput{
NSString * MOBILE = @ "^1 (3[0-9]|5[0-35-9]|8[025-9]|70|77) \\d{8}$";
NSString * CM = @ "^1 (34[0-8]| ( 3[5-9]|5[017-9]|8[278] \\d) \\d{7}$ ";
NSString * CU = @ "^1 (3[0-2]|5[256]|8[56]) \\d{8}$";
NSString * CT = @ "^1 ((33|53|8[09)) [0-9]|349] \\d{7}$";
Nspredicate *regextestmobile = [Nspredicate predicatewithformat:@ "Self MATCHES%@", MOBILE];
Nspredicate *REGEXTESTCM = [Nspredicate predicatewithformat:@ "Self MATCHES%@", CM];
Nspredicate *REGEXTESTCU = [Nspredicate predicatewithformat:@ "Self MATCHES%@", CU];
Nspredicate *REGEXTESTCT = [Nspredicate predicatewithformat:@ "Self MATCHES%@", CT];
BOOL res1 = [Regextestmobile evaluatewithobject:self];
BOOL res2 = [REGEXTESTCM evaluatewithobject:self];
BOOL Res3 = [Regextestcu evaluatewithobject:self];
BOOL res4 = [REGEXTESTCT evaluatewithobject:self];
if (res1 | | res2 | | res3 | | res4) {
return YES;
} else {
return NO;
}
}
3. Import #import "Nsstring+check.h" where needed
4. Method of Use: BOOL isphonenum = [Self.phoneTextField.text checkphonenuminput];
iOS development--Judging phone formats