IOS Tracking Limit textfield number of input digits

Source: Internet
Author: User

Implementation effect: Force users to enter only 16 digits, here is the use of credit card number input.

Enter the number of characters greater than 16, the color of the word to black, and no matter what continues to enter what content, only take the first 16 bits;

If it is less than 16 bits, the color of the word is set to red, and the setting is "invalid".

-(void) viewdidload{    [Super Viewdidload];    Check input box every 0.1 seconds    [Nstimer scheduledtimerwithtimeinterval:0.1 target:self selector: @selector (checkcardinfoinput) Userinfo:nil Repeats:yes];}
-(void) checkcardinfoinput{    BOOL isValid = YES;    if ([Self.cardNumberTextField.text length] >=) {        Self.cardNumberTextField.textColor = [Uicolor blackcolor];        Self.cardNumberTextField.text = [Self.cardNumberTextField.text substringwithrange:nsmakerange (0, +)];    }    else{        self.cardNumberTextField.textColor = [Uicolor redcolor];        IsValid = NO;    }       Other authentication        if (isValid = = YES) {self        . addcreditcardbutton.enabled = YES;        Self. Addcreditcardbutton.backgroundcolor = [Uicolor greencolor];    }    else{self        . addcreditcardbutton.enabled = NO;        Self. Addcreditcardbutton.backgroundcolor = [Uicolor graycolor];    }}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.