Textfield Delegate

VC.h


#import <UIKit/UIKit.h>

@interface ViewController : UIViewController


@property UIScrollView*userView,*loginView,*details;

@property UITextField * firstName,*lastName, * moblieTF, * cityName, * eMailTF,* passwordTF,* reTypePasswordTF;

@property UISegmentedControl * stateNames,* segmentNames,*genderNames, * agreeSegment;

@property UITextField * eMailTF2, * passwordTF2;

@property UIButton*login,*submit;
@property UILabel *label;
@property NSMutableArray *array;

@property UILabel * FNLB,* LNLB, * mobileLB, * genderLB,* cityLB, * stateLB, * eMailLB,* passwordLB,*rePWDLB;



@property UILabel *FN, *LN,*selectGender, *mobileN, *cityN, *stateN, *emailLogin, *pwdLogin,*rePWDLBLogin;
//@property NSString * selectedGender,*selectedStates;
//-(BOOL)validateFirstName:(NSString *)firstName;
//-(BOOL)validateLastName:(NSString *)lastName;
//-(BOOL)validatenNumber:(NSString*)numberCheck;
//-(BOOL)validateCity:(NSString*)cityCheck;
//-(BOOL)validateMail:(NSString*)mailCheck;
//-(BOOL)validatePassword:(NSString*)passwordCheck;
@end


VC.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController



- (void)viewDidLoad {
    
    [super viewDidLoad];
    [self elements];
    // Do any additional setup after loading the view, typically from a nib.
}
-(void)elements
{
    self.segmentNames=[[UISegmentedControl alloc]initWithItems:@[@"NEW USER",@"EXISTINGUSER"]];
    self.segmentNames.frame = CGRectMake(80, 30, 200, 30);
    self.segmentNames.apportionsSegmentWidthsByContent=YES;
    [self.segmentNames addTarget:self action:@selector(newUser:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:self.segmentNames];
}
-(void)newUser:(id)sender
{
    if(self.segmentNames.selectedSegmentIndex==0)
    {
        self.loginView.hidden=YES;
        
        self.userView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 70, 372, 595)];
        [self.userView setBackgroundColor:[UIColor lightGrayColor]];
        self.userView.contentSize=CGSizeMake(400, 800);
        [self.view addSubview:self.userView];
        
        
        self.firstName=[[UITextField alloc]initWithFrame:CGRectMake(30, 20, 150, 30)];
        self.firstName.backgroundColor=[UIColor clearColor];
        self.firstName.placeholder=@"firstName";
        self.firstName.borderStyle=UITextBorderStyleBezel;
      self.firstName.keyboardType=UIKeyboardTypeDefault;
        [self.userView addSubview:self.firstName];
        
        self.lastName=[[UITextField alloc]initWithFrame:CGRectMake(200, 20, 150, 30)];
        self.lastName.backgroundColor=[UIColor clearColor];
        self.lastName.placeholder=@"lastName";
        self.lastName.borderStyle=UITextBorderStyleBezel;
 self.lastName.keyboardType=UIKeyboardTypeDefault;
        [self.userView addSubview:self.lastName];
        
        
        
        self.genderNames=[[UISegmentedControl alloc]initWithItems:@[@" MALE",@"FEMALE"]];
        self.genderNames.frame = CGRectMake(100, 70, 200, 30);
        self.genderNames.apportionsSegmentWidthsByContent=YES;
        [self.userView addSubview:self.genderNames];
        
        
        self.moblieTF=[[UITextField alloc]initWithFrame:CGRectMake(30, 130, 150, 30)];
        self.moblieTF.backgroundColor=[UIColor clearColor];
        self.moblieTF.placeholder=@"enter mobile no";
       self.moblieTF.borderStyle=UITextBorderStyleBezel;
        self.moblieTF.keyboardType=UIKeyboardTypeNumberPad;
        
        [self.userView addSubview:self.moblieTF];
        
        
        
        self.cityName=[[UITextField alloc]initWithFrame:CGRectMake(30, 180, 150, 30)];
        self.cityName.backgroundColor=[UIColor clearColor];
        self.cityName.placeholder=@"city/town";
        self.cityName.borderStyle=UITextBorderStyleBezel;
       self.cityName.keyboardType=UIKeyboardTypeDefault;
        [self.userView addSubview:self.cityName];
        
        self.stateNames=[[UISegmentedControl alloc]initWithItems:@[@"SI",@"EI",@"NI",@"WI"]];
        self.stateNames.frame = CGRectMake(30, 230, 200, 30);
        self.stateNames.apportionsSegmentWidthsByContent=YES;
        [self.userView addSubview:self.stateNames];
        
        
        
        
        self.eMailTF=[[UITextField alloc]initWithFrame:CGRectMake(30, 290, 300, 30)];
        self.eMailTF.backgroundColor=[UIColor clearColor];
        self.eMailTF.placeholder=@"mani123@gmail.com";
        self.eMailTF.borderStyle=UITextBorderStyleBezel;
        self.eMailTF.keyboardType=UIKeyboardTypeEmailAddress;
        [self.userView addSubview:self.eMailTF];
        
        
        
        
        self.passwordTF=[[UITextField alloc]initWithFrame:CGRectMake(30, 350, 150, 30)];
        self.passwordTF.backgroundColor=[UIColor clearColor];
        self.passwordTF.placeholder=@"passwordText";
        self.passwordTF.borderStyle=UITextBorderStyleBezel;
        self.passwordTF.secureTextEntry=YES;
        self.passwordTF.keyboardType=UIKeyboardTypeDefault;
        
        [self.userView addSubview:self.passwordTF];
        
        
        
        
        self.reTypePasswordTF=[[UITextField alloc]initWithFrame:CGRectMake(30, 400, 190, 30)];
        self.reTypePasswordTF.backgroundColor=[UIColor clearColor];
        self.reTypePasswordTF.placeholder=@"reTypePassword";
        self.reTypePasswordTF.secureTextEntry=YES;
        self.reTypePasswordTF.borderStyle=UITextBorderStyleBezel;
       self.reTypePasswordTF.keyboardType=UIKeyboardTypeDefault;
        [self.userView addSubview:self.reTypePasswordTF];
        
        
        self.agreeSegment=[[UISegmentedControl alloc]initWithItems:@[@"AGREE",@"DISAGREE"]];
        self.agreeSegment.frame = CGRectMake(30, 470, 200, 30);
        self.agreeSegment.apportionsSegmentWidthsByContent=YES;
         [self.agreeSegment addTarget:self action:@selector(checkValdate ) forControlEvents:UIControlEventTouchUpInside];
        [self.agreeSegment addTarget:self action:@selector(action:) forControlEvents:UIControlEventValueChanged];
        
        [self.userView addSubview:self.agreeSegment];
        
        
        
        self.submit= [UIButton buttonWithType:UIButtonTypeSystem];
        self.submit.frame = CGRectMake(200, 520, 60, 30);
        self.submit.backgroundColor=[UIColor redColor];
        [self.submit setTitle:@"submit" forState:UIControlStateNormal];
        [self.submit addTarget:self action:@selector(submit: ) forControlEvents:UIControlEventTouchUpInside];
        // [self.submit addTarget:self action:@selector(checkValdate) forControlEvents:UIControlEventTouchUpInside];
              }
    else if (self.segmentNames.selectedSegmentIndex==1)
    {
        self.userView.hidden=YES;
        
        self.loginView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 70, 372, 595)];
        [self.loginView setBackgroundColor:[UIColor lightGrayColor]];
        
        [self.view addSubview:self.loginView];
        

        
        
        self.eMailTF2=[[UITextField alloc]initWithFrame:CGRectMake(30, 40, 200, 30)];
        self.eMailTF2.backgroundColor=[UIColor clearColor];
        self.eMailTF2.placeholder=@"username";
        self.eMailTF2.borderStyle=UITextBorderStyleBezel;
        [self.loginView addSubview:self.eMailTF2];
        
        
        self.passwordTF2=[[UITextField alloc]initWithFrame:CGRectMake(30, 100, 200, 30)];
        self.passwordTF2.backgroundColor=[UIColor clearColor];
        self.passwordTF2.placeholder=@"password";
        self.passwordTF2.secureTextEntry=YES;
        
        self.passwordTF2.borderStyle=UITextBorderStyleBezel;
        [self.loginView addSubview:self.passwordTF2];
        
        self.login= [UIButton buttonWithType:UIButtonTypeSystem];
        self.login.frame =CGRectMake(60, 150, 90, 40);
        self.login.backgroundColor=[UIColor redColor];
        [self.login setTitle:@"login" forState:UIControlStateNormal];
        [self.login addTarget:self action:@selector(login1:) forControlEvents:UIControlEventTouchUpInside];
        [self.loginView addSubview:self.login];
        
        
    }
}
-(void)action:(id)sender

{
    if (self.agreeSegment.selectedSegmentIndex==0) {
        
        self.submit.hidden=NO;
        [self.userView addSubview:self.submit];

    }
    else if(self.agreeSegment.selectedSegmentIndex==1){
        UIAlertView * submitAlert =[[UIAlertView alloc]initWithTitle:@"alert" message:@"press agree" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
        [submitAlert show];

    }
}
-(void)submit:(id)sender{
    if ([self.firstName.text isEqualToString:@""] || [self.lastName.text isEqualToString:@""] || [self.moblieTF.text isEqualToString:@""] || [self.cityName.text isEqualToString:@""] || [self.eMailTF.text isEqualToString:@""]|| [self.passwordTF.text isEqualToString:@""] ||  [self.reTypePasswordTF.text isEqualToString:@""]||[[self.stateNames titleForSegmentAtIndex:self.stateNames.selectedSegmentIndex] isEqualToString:@""]||[[self.genderNames titleForSegmentAtIndex:self.genderNames.selectedSegmentIndex] isEqualToString:@""])    {
        
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Message" message:@"Check All Details" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
        
        [alertView show];
        NSLog(@"all are not filled");
        
    }
    
    if(![self.reTypePasswordTF.text isEqualToString:self.passwordTF
        .text]){
        
        UIAlertView * PWDAlert =[[UIAlertView alloc]initWithTitle:@"alert" message:@"check Password" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
        [PWDAlert show];
        
        NSLog(@"all are pw correct");
    }
    else{
        
        self.userView.hidden=YES;
        UIAlertView * successAlert =[[UIAlertView alloc]initWithTitle:@"alert" message:@"success" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
        [successAlert show];
            
    }
    

    
}

    

-(BOOL)validateFirstName:(NSString*)firstNameCheck
{
    NSString *firstName = @"[a-zA-Z][a-zA-Z]*";
    NSPredicate *firstNameTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", firstName];
    return [firstNameTest evaluateWithObject:firstNameCheck];
}
-(BOOL)validateLastName:(NSString*)lastNameCheck
{
    NSString *lastName = @"[a-zA-Z][a-zA-Z]*";
    NSPredicate *lastNameTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", lastName];
    return [lastNameTest evaluateWithObject:lastNameCheck];
}
-(BOOL)validateNumber:(NSString*)numberCheck
{
    NSString *mobileNumber = @"[0-9][0-9]*";
    NSPredicate *mobileNumberTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", mobileNumber];
    return [mobileNumberTest evaluateWithObject:mobileNumber];
}
-(BOOL)validateCity:(NSString*)cityCheck
{
    NSString *cityName = @"[A-Za-z][A-Za-z]*";
    NSPredicate *cityTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", cityName];
    return [cityTest evaluateWithObject:cityName];
}
-(BOOL)validateMail:(NSString*)mailCheck
{
    NSString *mail = @"[a-zA-Z0-9+.@][a-zA-Z0-9+.@]*";

    NSPredicate *mailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", mail];
    return [mailTest evaluateWithObject:mailCheck];
}
-(BOOL)validatePassword:(NSString*)passwordCheck
{
        NSString *password = @"[a-zA-Z0-9][a-zA-Z0-9]*";
        NSPredicate *passwordTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", password];
        return [passwordTest evaluateWithObject:password];
}
-(BOOL)checkValdate
{
BOOL    validateFN =[self validateFirstName:self.firstName.text];
BOOL    validateLN =[self validateLastName:self.lastName.text];
BOOL    validateNumber =[self validateNumber:self.moblieTF.text];
BOOL    validateCity =[self validateCity:self.cityName.text];
BOOL    validateEmail =[self validateMail:self.eMailTF.text];
BOOL    validatePassword =[self validatePassword:self.passwordTF.text];
    
    if (validateFN == true && validateLN == true && validateNumber == true && validateCity ==true&& validateEmail == true && validatePassword == true)
    {
        self.submit.hidden=NO;
        [self.userView addSubview:self.submit];

        UIAlertView * alertAll =[[UIAlertView alloc]initWithTitle:@"alert" message:@"correct" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
        [alertAll show];
        NSLog(@"all are correct");
    }
    
    else{
        UIAlertView * alertAll =[[UIAlertView alloc]initWithTitle:@"alert" message:@"fill details " delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
        [alertAll show];
 NSLog(@"all are not correct");
    }
    return YES;
}

-(void)login1:(id)sender
{
    if( [self.eMailTF.text isEqualToString:@""] || [self.passwordTF.text isEqualToString:@""]  )
    {
        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Message" message:@"Check All Details" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
        
        [alertView show];
        NSLog(@"all are not filled");
        
    }

   else  if( [self.eMailTF.text isEqualToString:self.eMailTF2.text] && [self.passwordTF.text isEqualToString:self.passwordTF2.text]  )
        
    {
        self.loginView.hidden=YES;
        self.userView.hidden=YES;
        
        
        self.details=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 80, [[UIScreen mainScreen]bounds].size.width, [[UIScreen mainScreen]bounds].size.height)];
        [self.details setBackgroundColor:[UIColor lightGrayColor]];
        
        [self.view addSubview:self.details];
        
        
        self.array=[[NSMutableArray alloc]initWithObjects:self.firstName.text,self.lastName.text ,[self.genderNames titleForSegmentAtIndex:self.genderNames.selectedSegmentIndex],self.moblieTF.text,self.cityName.text,[self.stateNames titleForSegmentAtIndex:self.stateNames.selectedSegmentIndex],self.eMailTF.text,self.passwordTF.text,nil];
        
        NSLog(@"array %@",self.array );
        
        //[self removeAction];
        
        
        self.FNLB=[[UILabel alloc]initWithFrame:CGRectMake(30, 80, 100, 30)];
        [self.FNLB setText:@"firstName"];
        [self.details addSubview:self.FNLB];
        
        
        
        
        self.LNLB=[[UILabel alloc]initWithFrame:CGRectMake(30, 130, 100, 40)];
        [self.LNLB setText:@"lastName"];
        [self.details addSubview:self.LNLB];
        
        self.genderLB=[[UILabel alloc]initWithFrame:CGRectMake(30, 180, 150, 40)];
        [self.genderLB setText:@"gender"];
        [self.details addSubview:self.genderLB];
        
        self.mobileLB=[[UILabel alloc]initWithFrame:CGRectMake(30, 220, 100, 40)];
        [self.mobileLB setText:@"Mobile"];
        [self.details addSubview:self.mobileLB];
        
        self.cityLB=[[UILabel alloc]initWithFrame:CGRectMake(30, 270, 100, 40)];
        [self.cityLB setText:@"city"];
        [self.details addSubview:self.cityLB];
        
        
        self.stateLB=[[UILabel alloc]initWithFrame:CGRectMake(30, 320, 150, 40)];
        [self.stateLB setText:@"state"];
        [self.details addSubview:self.stateLB];
        
        self.eMailLB=[[UILabel alloc]initWithFrame:CGRectMake(30, 370, 100, 40)];
        
        [self.eMailLB setText:@"eMail"];
        [self.details addSubview:self.eMailLB];
        
        self.passwordLB=[[UILabel alloc]initWithFrame:CGRectMake(30, 420, 100, 40)];
        [self.passwordLB setText:@"password"];
        [self.details addSubview:self.passwordLB];
        
        
        
        self.FN=[[UILabel alloc]initWithFrame:CGRectMake(150, 80, 150, 30)];
        [self.FN setText:self.array[0]];
        [self.details addSubview:self.FN];
        
        
        
        
        self.LN=[[UILabel alloc]initWithFrame:CGRectMake(150, 130, 150, 40)];
        [self.LN setText:self.array[1]];
        [self.details addSubview:self.LN];
        
        self.selectGender=[[UILabel alloc]initWithFrame:CGRectMake(150, 180, 150, 40)];
        [self.selectGender setText:self.array[2]];
        [self.details addSubview:self.selectGender];
        
        self.mobileN=[[UILabel alloc]initWithFrame:CGRectMake(150, 220, 150, 40)];
        [self.mobileN setText:self.array[3]];
        [self.details addSubview:self.mobileN];
        
        self.cityN=[[UILabel alloc]initWithFrame:CGRectMake(150, 270, 150, 40)];
        [self.cityN setText:self.array[4]];
        [self.details addSubview:self.cityN];
        
        
        self.stateN=[[UILabel alloc]initWithFrame:CGRectMake(150, 320, 150, 40)];
        [self.stateN setText:self.array[5]];
        [self.details addSubview:self.stateN];
        
        self.emailLogin=[[UILabel alloc]initWithFrame:CGRectMake(150, 370, 150, 40)];
        [self.emailLogin setText:self.array[6]];
        [self.details addSubview:self.emailLogin];
        
        self.pwdLogin=[[UILabel alloc]initWithFrame:CGRectMake(150, 420, 150, 40)];
        [self.pwdLogin setText:self.array[7]];
        [self.details addSubview:self.pwdLogin];

        
    }
    
    else
    {
        
        UIAlertView * mailAlert =[[UIAlertView alloc]initWithTitle:@"alert" message:@"wrong" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
        [mailAlert show];
        
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
Previous
Next Post »