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 6989341
In Process

The Archive Base Latest Questions

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

I am currently restricting the user to write in a text from more than

  • 0

I am currently restricting the user to write in a text from more than 4 character.

For this i am using this piece of code

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

    if ([textField.text length] == 4)
        return NO;
    else
        return YES;    
}

Its working fine and it do not allow the user to write more than 4 character.

But when i try to delete the existing character.The keyboard delete option is not working.

How to solve this problem

  • 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-27T19:11:57+00:00Added an answer on May 27, 2026 at 7:11 pm

    When shouldChangeCharactersInRange method is called text field still has an old value and so if its length is 4 you’re stuck. Better way to validate input will be to calculate what string you’re going to have in a field after the change and check if it is valid:

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString: (NSString *)string{
        NSString *newString = [textField.text stringByReplacingCharactersInRange:range
                                                             withString:string];
        return [newString length] <= 4;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently using criteria to retrieve the details of a user, but when
I'm trying to write a simple shell in prolog. I currently query the user
Currently I'm doing some unit tests which are executed from bash. Unit tests are
Where do I get information about the currently connected user? That is, how does
i am implementing this code : if ([SKPaymentQueue canMakePayments]) { // Display a store
Our system using HttpContext.Current.Session(Client) to store the current user info. One property in the
I need a method of stopping concurrent logins using PHP/MySQL. The current setup Currently
I have some code in place currently to intercept all Cut, Copy and Paste
I'm using the JQuery DatePicker to have the user pick a date and have
Currently our queries add a variety of Restrictions to ensure the results are considered

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.