In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Xiaobian to share with you how regular expressions to verify user names, passwords, mobile phone numbers, ID card functions, I believe that most people do not know much, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!
Example
/ / user name + (BOOL) validateUserName: (NSString *) name {NSString * userNameRegex = @ "^ [A-Za-z0-9] {3 NSPredicate predicateWithFormat:@ 20} + $"; NSPredicate * userNamePredicate = [NSPredicate predicateWithFormat:@ "SELF MATCHES% @", userNameRegex]; BOOL B = [userNamePredicate evaluateWithObject:name]; return B;} / / password + (BOOL) validatePassword: (NSString *) passWord {NSString * passWordRegex = @ "^ [a-zA-Z0-9] {6jue 20} + $"; NSPredicate * passWordPredicate = [NSPredicate predicateWithFormat:@ "SELF MATCHES% @", passWordRegex] Return [passWordPredicate evaluateWithObject:passWord];} / / determine whether the mobile phone number format is correct + (BOOL) valiMobile: (NSString *) mobile {mobile = [mobile stringByReplacingOccurrencesOfString:@ "" withString:@ ""]; if (mobile.length! = 11) {return NO } else {/ * regular expression of mobile number segment * / NSString * CM_NUM = @ "^ ((13 [4-9])) | (15 [0-2 7-9]) | (178) | (18 [2-4 recorder 7-8]))\ d {8} | (1705)\\ d {7} $" / * * regular expression for Unicom segment * / NSString * CU_NUM = @ "^ ((13 [0-2])) | (145) | (15 [5-6]) | (17) | (18 [5pc6]))\\ d {8} | (1709)\ d {7} $" / * * regular expression of electrical signal segment * / NSString * CT_NUM = @ "^ ((133c) | (153c) | (177C)\\ d {8} $"; NSPredicate * pred1 = [NSPredicate predicateWithFormat:@ "SELF MATCHES% @", CM_NUM]; BOOL isMatch2 = [pred1 evaluateWithObject:mobile]; NSPredicate * pred2 = [NSPredicate predicateWithFormat:@ "SELF MATCHES% @", CU_NUM]; BOOL isMatch3 = [pred2 evaluateWithObject:mobile] NSPredicate * pred3 = [NSPredicate predicateWithFormat:@ "SELF MATCHES% @", CT_NUM]; BOOL isMatch4 = [pred3 evaluateWithObject:mobile]; if (isMatch2 | | isMatch3 | | isMatch4) {return YES;} else {return NO } / * method to verify whether the ID card number is correct * * @ param IDNumber passes it into the ID card number string * * @ return returns YES or NO indicating whether the ID card number conforms to the national standard * / + (BOOL) isCorrect: (NSString *) IDNumber {NSMutableArray * IDArray = [NSMutableArray array]; / / traverses the ID card string and stores it in the array if (IDNumber.length = 18) {for (int I = 0) I < 18; iTunes +) {NSRange range = NSMakeRange (I, 1); NSString * subString = [IDNumber substringWithRange:range]; [IDArray addObject:subString];}} else {for (int I = 0; I < 15; iTunes +) {NSRange range = NSMakeRange (I, 1); NSString * subString = [IDNumber substringWithRange:range]; [IDArray addObject:subString] }} / coefficient array NSArray * coefficientArray = [NSArray arrayWithObjects:@ "7", @ "9", @ "10", @ "5", @ "8", @ "4", @ "2", @ "1", @ "6", @ "3", @ "7", @ "9", @ "10", @ "5", @ "8", @ "4", @ "2", nil] / / the remainder array NSArray * remainderArray = [NSArray arrayWithObjects:@ "1", @ "0", @ "X", @ "9", @ "8", @ "7", @ "6", @ "5", @ "4", @ "3", @ "2", nil]; / / the sum of each ID number multiplied by the corresponding coefficient and int sum = 0 If (IDNumber.length = = 18) {for (int I = 0; I < 17; iArray +) {int coefficient = [coincidentArray [I] intValue]; int ID = [ID Array [I] intValue]; sum + = coefficient * ID;}} else {for (int I = 0; I < 14; iArray +) {int coefficient = [coexistent Array [I] intValue]; int ID = [ID Array [I] intValue]; sum + = coefficient * ID }} / / the number NSString * str = remainderArray [(sum% 11)] corresponding to the remainder divided by 11; / / the last digit of the ID card number NSString * string; if (IDNumber.length = = 18) {string = [IDNumber substringFromIndex:17];} else {string = [IDNumber substringFromIndex:14] } / / if this number is the same as the last digit of the ID card, it conforms to the national standard. Return YES if ([str isEqualToString:string]) {return YES;} else {return NO;}} above is all the contents of the article "how to verify the user name, password, mobile phone number and ID card function of regular expressions". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.