Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6936129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:11:38+00:00 2026-05-27T12:11:38+00:00

I am writing validation for my textfield, I found something interesting that whether I

  • 0

I am writing validation for my textfield, I found something interesting that whether I can check how many digits I am typing into the textfield at real time. My text field input must be 8 digit number. So I want to change the text inside the text field to green colour when I reach 8 digit and change colour when it’s not.

How can I do that? Please help me, thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:11:39+00:00Added an answer on May 27, 2026 at 12:11 pm

    Using -textField:shouldChangeCharactersInRange:replacementString: is probably a bad solution because it fires before the text field updates. This method should probably be used when you want to change the text of the text field before the keyboard automatically updates it. Here, you probably want to simply use target-action pairing when editing value changes:

    [textField addTarget:self action:@selector(checkTextField:) forControlEvents:UIControlEventEditingChanged];
    

    Then, in - (void)checkTextField:(id)sender, try this:

    UITextField *textField = (UITextField *)sender;
    if ([textField.text length] == 8) {
        textField.textColor = [UIColor greenColor]; // No cargo-culting please, this color is very ugly...
    } else {
        textField.textColor = [UIColor blackColor];
        /* Must be done in case the user deletes a key after adding 8 digits,
           or adds a ninth digit */
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a PropertiesMustMatch validation attribute that can take a string property name as
I am writing a client-side validation function for CustomValidator and I need to check
I am currently writing some unit tests for a business-logic class that includes validation
Currently I'm writing a unit test for a component that does datetime specific validation.
I'm writing validation regex in c# - basically need to ensure that property does
I am writing a custom validation set that will display all missing elements on
I am writing a basic jQuery form validation script and I have something like
I am writing a Macro in excel VBA that creates a data validation list
I am currently writing a lot of MySQL queries and noticed that I can
I am writing some validation code. The code will take data passed into a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.