Created
September 23, 2016 05:42
-
-
Save jenhausu/18abe6819b02a65898c8670ba18d8d0d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| + (BOOL)password:(NSString *)string { | |
| if ([self checkFormat:string withPattern:@"^([a-zA-Z]+\\d+|\\d+[a-zA-Z]+)[a-zA-Z0-9]*$" matchingOptions:NSRegularExpressionCaseInsensitive]) { | |
| if (string.length >= 6 && string.length <= 12) { | |
| for (NSInteger l = 0 ; l < string.length - 2 ; l++ ) { | |
| NSString *subString = [string substringWithRange:NSMakeRange(l, 3)]; | |
| // 檢查數字 | |
| for (NSInteger i = 0 ; i <= 9 ; i++ ) { | |
| if ([subString isEqualToString:[NSString stringWithFormat:@"%ld%ld%ld", i, i, i]]) { // 不可連續三個重複的數字 | |
| return NO; | |
| } else if ([subString isEqualToString:[NSString stringWithFormat:@"%ld%ld%ld", i, i + 1, i + 2]]) { // 不可連續三個連續的數字(123, 234...等) | |
| return NO; | |
| } | |
| } | |
| // 檢查字母 | |
| for (char alphabet = 'a' ; alphabet <= 'z' ; alphabet++ ) { | |
| if ([subString isEqualToString:[NSString stringWithFormat:@"%c%c%c", alphabet, alphabet, alphabet]]) { // 檢查有無連續三個一樣的小寫英文字母 | |
| return NO; | |
| } else if ([subString isEqualToString:[NSString stringWithFormat:@"%c%c%c", alphabet, alphabet + 1, alphabet + 2]]) { // 檢查有無連續三個連續的小寫英文字母 | |
| return NO; | |
| } | |
| } | |
| for (char alphabet = 'A' ; alphabet <= 'Z' ; alphabet++ ) { | |
| if ([subString isEqualToString:[NSString stringWithFormat:@"%c%c%c", alphabet, alphabet, alphabet]]) { // 檢查有無連續三個一樣的大寫英文字母 | |
| return NO; | |
| } else if ([subString isEqualToString:[NSString stringWithFormat:@"%c%c%c", alphabet, alphabet + 1, alphabet + 2]]) { // 檢查有無連續三個連續的大寫英文字母 | |
| return NO; | |
| } | |
| } | |
| } | |
| return YES; | |
| } | |
| } | |
| return NO; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment