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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:16:32+00:00 2026-06-12T17:16:32+00:00

I need to allow the end user enter only 1-9 digits: – (BOOL)textField:(UITextField *)textField

  • 0

I need to allow the end user enter only 1-9 digits:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
        NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
        if([newString length]>=1)
        {
            NSString *sepStr=[newString substringToIndex:1];
            return !([sepStr length]>1);
        }

        if ([string length] == 0 && range.length > 0){
            textField.text = [textField.text stringByReplacingCharactersInRange:range withString:string];
            return NO;
        }
        NSCharacterSet *nonNumberSet = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789"] invertedSet];
        if ([string stringByTrimmingCharactersInSet:nonNumberSet].length > 0)return YES;
        return NO;
    }

But it’s still possible to enter more than 1 number.
Please help to find an error.

  • 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-06-12T17:16:33+00:00Added an answer on June 12, 2026 at 5:16 pm

    Just add this to your first test :

    if ([newString length] > 1)
        return NO;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need allow registered front end users to add, remove images to image gallery.
I am building an app where I need to allow a user to add
I have a situation where the end user is allowed to enter an arbitrary
I am creating a web form on asp.net that will allow the end user
I have a need to allow for a user to download an event that
I need to allow users to upload PDF documents that other users will read.
I need to allow users to select an assembly in much the same way
I need to allow a consultant to connect to SSIS on a SQL Server
I need to allow multiple Products to be present in a Cart. I do
I need to allow multiple downloading of small documents in Rails, preferably using Paperclip

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.