Sunday 10 March 2013

(21)Validation for allowed Email Format for textfields


Ø (21)Validation for allowed Email Format for textfields

- (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];
    }
   
}         
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDkrJIzmOXlgl-oN85i3ZgjmIVQBxcR_OaINX5w6555V_FVjp8worKwLkxbzfUkGe2NTHzUelT_GH7NVJ4JSOaUEhvT3jF7WK2mq40xNPrXYfoikos3zhwHQOT1GatWnOKA19kKoQMUAb_/s1600/sync-crm-iphone-3.png
 - (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;
}

Here nameIndex  is my array with contact details.


No comments:

Post a Comment