Anand ios Anand ios - 5 months ago 19
Objective-C Question

How to set Minimum and Maximum limit to Uitextfield?

i need to set minimum and maximum limit value to one single textfield i.e the number should start with minimum 2 digits and maximum 5 digits here i tried some methods

-(BOOL)validatenumber:(NSString*)Number{

if ([Number length ]>=2) {
return NO;
}

return YES;


}

Answer
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{

NSInteger inte = [textField.text intValue];
if (inte <5 || inte > 2)

    return NO;
else 
    return YES;
}

Swift

override func textFieldShouldReturn(textField: UITextField) -> Bool {
var inte: Int = CInt(textField.text!)!
if inte < 5 || inte > 2 {
    return false
}
else {
    return true
}
}
Comments