Thursday, 20 February 2014

Text field accept only numbers (Max. 10 numbers)

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{

    if (textField.keyboardType == UIKeyboardTypeNumberPad)
    {
        if (!(textField.text.length<10||[string isEqualToString:@""])||[string rangeOfCharacterFromSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]].location != NSNotFound)
        {
            

            return NO;
        }
    }

    return YES;
}

No comments:

Post a Comment