views:

19

answers:

2

hi friends .. i have a multiple textfields in my nib file. i want to decide input range in my one textfield 6-16 digits.and don't wanna to change some other textfield input.for that i was made a method called tflimit as below.

-(IBAction)tflimit:(id)sender
{      
    if([textfields1.text length]>=15 )
    {
         [textfields1 resignFirstResponder]; 
    }   
}

for this method i can input only 16 digits input. how can i decide the range(6-16) of input in the textfield,without changing other codes. please help me.

+1  A: 

You can filter user input in textField:shouldChangeCharactersInRange:replacementString: method in text field delegate:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    if (textField == textfields1){// Apply logic only to required field
        NSString* newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
        return [newString length] < 16 && [newString length] > 5;
    }
    return YES;
}

Note that to work correctly this method require textfield to be pre-populated with text at least 5 characters long.

Vladimir
thnks for ur reply..but i have to input from keyboard without populating any prior input.and for implemnting this method i have to declare the <UITextFieldDelegate> in .h file.and for implementing this method my all fields are not responded.how to do perform my task.please help me .
mukeshpawar
To avoid pre-populating you must add extra logic for checking minimum text length - e.g. check for that case only in case characters are being deleted (that is when replacementString is empty). To make that work your controller must conform to UITextFieldDelegate protocol, but sorry don't understand what problem you have with that.
Vladimir
A: 

thanks Vladimir for ur reply..but i have to input from keyboard without populating any prior input.and for implementing this method i have to declare the in .h file.and for implementing this method my all fields are not responded.how to do perform my task.please help me .

mukeshpawar