if([self validatePhone:searchBar.text])
NSlog(“Valid mobile number”);
else
NSlog(“Invalid mobile number”);
- (BOOL)validatePhone:(NSString *)phoneNumber
{
// NSString *phoneRegex = @"^((\\+)|(00))[0-9]{6,14}$";
NSString * phoneRegex = @"^(\\+?)(\\d{10})$”;
NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", phoneRegex];
return [phoneTest evaluateWithObject:phoneNumber];
}
-(BOOL) validateEmail:(NSString *)email
{
NSString *emailRegex = @"^[^-._]+([A-Z0-9a-z]|([-._][^-._]))+[^-._]?@[A-Za-z0-9-]+\\.[A-Za-z]{2,4}$";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailTest evaluateWithObject:email];
}
No comments:
Post a Comment