Regular expressions to determine cell phone number format
-(BOOL) Checktel: (NSString *) str
{
if ([str length] = = 0) {
uialertview* alert = [[Uialertview alloc] initwithtitle:nslocalizedstring (@ "data_null_prompt", nil) message: Nslocalizedstring (@ "Tel_no_null", nil) delegate:nil cancelbuttontitle:@ "OK" otherbuttontitles:nil, nil];
[Alert show];
return NO;
}
1[0-9]{10}
^ ((13[0-9]) | (15[^4,\\d]) | (18[0,5-9])) \\d{8}$
NSString *regex = @ "[0-9]{11}";
NSString *regex = @ "^ ((13[0-9]) | ( 17[0-9]) | (147) | (15[^4,\\d]) | (18[0,5-9])) \\d{8}$ ";
Nspredicate *pred = [Nspredicate predicatewithformat:@ "Self MATCHES%@", regex];
BOOL IsMatch = [pred evaluatewithobject:str];
if (!ismatch) {
uialertview* alert = [[Uialertview alloc] initwithtitle:@ "Prompt" message:@ "Please enter the correct mobile number" Delegate:nil cancelbuttontitle:@ " OK "otherbuttontitles:nil, nil";
[Alert show];
return NO;
}
return YES;
}
Call the time
if (![ Self CheckTel:self.phoneText.text]) {
Incorrect logic for cell phone numbers;
Return
}
Else
{
The correct logic of the cell phone number;
}
Regular expression to determine the phone number