Whether the web is a mobile phone, the user registration when the time is large number of times need mobile phone number and e-mail address, and some apps can only use mobile phone number registration, iOS mailbox is relatively simple, but mobile phone number verification found a bit online, found that the three operators of the number segment changes, Through the latest number segment to determine the user's mobile phone verification error probability will be small, if there is missing number segment, welcome to Add.
/* Mobile authentication */+ (BOOL) Ismobilenumber: (NSString *) mobilenum {/** * mobile number * Mobile: 134/135/136/137/138/139/150/151/152/157 /158/159/182/183/184/187/188/147/178 * Unicom: 130/131/132/155/156/185/186/145/176 * Telecom: 133/153/180/181/189/177 * * NSString *mobile = @ "^1 (3[0-9]|5[0-35-9]|8[025-9]) \\d{8}$"; /** * Mobile: China Mobile * 134[0-8]/135/136/137/138/139/150/151/152/157/158/159/182/183/184/187/188/147/178 * * NSString *cm = @ "^1 (34[0-8]| ( 3[5-9]|5[0127-9]|8[23478]|47|78) \\d) \\d{7}$ "; /** * Unicom: China Unicom * 130/131/132/152/155/156/185/186/145/176 * * NSString *CU = @ "^1 (3[0-2]|5[256]|8[56 ]|45|76) \\d{8}$ "; /** * China Telecom: Chinese Telecom * 133/153/180/181/189/177 * * NSString *ct = @ "^1 ((33|53|77|8[019)) [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]; if ([regextestmobile evaluatewithobject:mobilenum] = = YES) | | ([regextestcm evaluatewithobject:mobilenum] = = YES) | | ([regextestct evaluatewithobject:mobilenum] = = YES) | | ([regextestcu evaluatewithobject:mobilenum] = = YES)) {return YES; } else {return NO; }}/* Mailbox Verification */+ (BOOL) Isvalidateemail: (NSString *) Email {nsstring *emailregex = @ "[a-z0-9a-z._%+-][email protected] [A-za-z0-9.-]+\\. [A-za-z] {2,4} "; Nspredicate *emailtest = [Nspredicate predicatewithformat:@ "Self MATCHES%@", Emailregex]; return [Emailtest Evaluatewithobject:email];}
iOS Development-uitextfield Mobile phone number and email verification