hi i am new iphone developer.my problem is i do one app ie user registration form in that form(username,password,email) and add these textfield values to array to displat on tableview and take one button when i enter data in textfields and click that button another view display and all user data display on tableview i write code for that but my problem is with out enter data in textfield and click button display alertview but i don't how to validate email textfield while enter data in textfield,please help to i want to display message while enter data in email textfield(alertmsg-enter email aaa@gmail.com formate like)
            Asked
            
        
        
            Active
            
        
            Viewed 210 times
        
    3 Answers
1
            
            
        For empty text field you can use following method :
-(BOOL) emptyCheck:(NSString *)textFieldtext
{
    return [[textFieldtext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]count]<=0;
}
for email you can use NSRegularExpression class and specify regEx format for email.
Thanks
 
    
    
        Ravin
        
- 8,544
- 3
- 20
- 19
1
            
            
        try this What are best practices for validating email addresses in Objective-C for iOS 2.0? , hope this will help
 
    
    
        Community
        
- 1
- 1
 
    
    
        Kshitiz Ghimire
        
- 1,716
- 3
- 18
- 37
0
            
            
        Use the follwing code for email validation:-
NSString *emailRegEx = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
        NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegEx];
        //Valid email address
        if ([emailTest evaluateWithObject:textField.text] == YES) 
        {
}
else {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"E-Mail Field Not In proper Format"  message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil,nil];
            [alert show];
            [alert release];
        }
 
    
    
        Gypsa
        
- 11,230
- 6
- 44
- 82
