- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- (BOOL)validateLoginData
{
self.phone = [Utils phoneFromFormat:[_loginMaskField maskedTextField].text];
if(![Utils validatePhone:self.phone]) {
[_loginMaskField shakeView]; // <-- Здесь автор анимирует вьюху ввода телефона.
return NO;
}
<...>
}
#pragma mark - Telephone mask
+ (NSString *)phoneFromFormat:(NSString *)format
{
int d = 1;
if(format.length == kPhonelength + d) //17
{
const char *cFormatString = [format UTF8String];
char *phoneString = malloc(10 * sizeof(char));
phoneString[0] = cFormatString[5 + d];
phoneString[1] = cFormatString[6 + d];
phoneString[2] = cFormatString[7 + d];
phoneString[3] = cFormatString[9 + d];
phoneString[4] = cFormatString[10 + d];
phoneString[5] = cFormatString[12 + d];
phoneString[6] = cFormatString[13 + d];
// phoneString[7] = cFormatString[15];
// phoneString[8] = cFormatString[16];
// phoneString[9] = '\0';
phoneString[7] = '\0';
NSString *phone = [NSString stringWithUTF8String:phoneString];
free(phoneString);
return phone;
}
else {
return nil;
}
}
+ (BOOL)validatePhone:(NSString *)phone
{
if(phone.length == kPhoneCountDigits)
{
NSString *regexpString = @"^[0-9][0-9]*$";
NSPredicate *test = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regexpString];
return [test evaluateWithObject:phone];
}
else {
return NO;
}
}
Валидируем введённый номер телефона. Кажется, я нашёл нового Евгения.
kyzmitch 25.09.2015 15:47 # 0
MAKAKA 30.03.2021 01:05 # +1
phoneString[0] = cFormatString[5 + d];
phoneString[1] = cFormatString[6 + d];
phoneString[2] = cFormatString[7 + d];
phoneString[3] = cFormatString[9 + d];
phoneString[4] = cFormatString[10 + d];
phoneString[5] = cFormatString[12 + d];
phoneString[6] = cFormatString[13 + d];
JloJle4Ka 30.03.2021 09:05 # 0