开发者

how to displat alertmessage while enter text in textfiled

开发者 https://www.devze.com 2023-02-25 00:28 出处:网络
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 but

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 valid开发者_高级运维ate 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)


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


try this What are best practices for validating email addresses in Objective-C for iOS 2.0? , hope this will help


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];

        }
0

精彩评论

暂无评论...
验证码 换一张
取 消