Wednesday 18 December 2013

Validation for allowed Email Format for text fields in iPhone

- (void)textFieldDidEndEditing:(UITextField *)textField
{

   
    NSString *emailString = textField.text;
  
    NSString *emailReg = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",emailReg];
    if (([emailTest evaluateWithObject:emailString] != YES) || [emailString isEqualToString:@""])
    {
        UIAlertView *loginalert = [[UIAlertView alloc] initWithTitle:@" Enter Email in" message:@"abc@example.com format" delegate:self
                                                   cancelButtonTitle:@"OK" otherButtonTitles:nil];
       
        [loginalert show];
    }
   
}         



 - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
     NSMutableArray *sectionedArray = [[[NSMutableArray alloc]init]autorelease]; 
      for(char c ='A' ; c <= 'Z' ;  c++)
      {
          [sectionedArray addObject:[NSString stringWithFormat:@"%c",c]];
       }
 return sectionedArray;
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index 
{
    NSInteger count = 0;
    for(NSString *character in nameIndex)
    {
        if([character isEqualToString:title])
        {
            return count;
        }
        count ++;
    }
    return 0;
}

No comments:

Post a Comment

Comment