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

  • Home
  • SEARCH
  • 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 6897469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:10:21+00:00 2026-05-27T07:10:21+00:00

I have searched the site for my answer, however I think it is also

  • 0

I have searched the site for my answer,
however I think it is also how I got myself into this problem.

I’m trying to limit my 1 and only text field to 10 characters and only numbers.

Below is code mostly off other questions on this site.
What I am trying to do is mash this code together for my limits

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:LEGAL] invertedSet];
    NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
    NSString *newString = [myTextField.text stringByReplacingCharactersInRange:range withString:filtered]; 
    return !([newString length] > 10);
}

There are no problems with my build until I click my textfield… but I get a green arrow warning stating ” thread stopped at breakpoint 1 ”
I’ve tried a few different things now, but now feel I am stumped, I’m hoping this is something real easy for someone here…

they will work individually (one or the other) with the code below, but I can’t seem to get them working together.

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

This will limit my input to 10
and …

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSCharacterSet *cs = [[NSCharacterSet characterSetWithCharactersInString:LEGAL] invertedSet];
    NSString *filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];
    return [string isEqualToString:filtered];
}

This also restricts my input to numbers only with no problems.
provided I defined LEGAL as only numbers…

I just can’t seem to get them to work together…
Can anyone help me with this one ???

  • 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-27T07:10:22+00:00Added an answer on May 27, 2026 at 7:10 am

    There are many ways to do this, but I think this might be the most understandable:

    -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
        // Check for non-numeric characters
        NSUInteger lengthOfString = string.length;
        for (NSInteger loopIndex = 0; loopIndex < lengthOfString; loopIndex++) {
            unichar character = [string characterAtIndex:loopIndex];
            if (character < 48) return NO; // 48 unichar for 0
            if (character > 57) return NO; // 57 unichar for 9
        }
        // Check for total length
        NSUInteger proposedNewLength = textField.text.length - range.length + string.length;
        if (proposedNewLength > 10) return NO;
        return YES;
    }
    

    The first section essentially check a non-empty string for characters that are not between ‘0’ and ‘9’ if it finds one anywhere in the new string it rejects the edit. The second determines what the length of the text will be if the editing is completed and compares to 10 if it’s to high it rejects the edit. If the function passes all those tests then the edit is allowed.

    There are no problems with my build until I click my textfield… but
    I get a green arrow warning stating " thread stopped at breakpoint 1 "

    You have apparently set a breakpoint in your textField:shouldChangeCharactersInRange:replacementString: method. If your not familiar with breakpoints they look like this: (The blue arrow on the row numbers column) And you can toggle whether or not they are enabled with the button pictured on the right:

    enter image description here enter image description here

    Breakpoints are very handy, and I suggest you learn to use them. But for now simply click on the breakpoint and drag it from the column, like an icon from the dock, or toggle that option off.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have searched the site for this simple problem but cant find an answer.
I have searched this site for an answer and found many responses to unsigned/signed
i have searched this site back and forth withoutfinding a clear answer for what
I have searched this site and also googled but can't seem to find the
I have searched the site and I haven't found an answer to my problem.
I have searched both Google and this site to find an answer. I have
I've searched this site and I can't seem to find an answer. I have
I have searched this site and Google and even though the idea is pretty
Preface: I am sure this is incredibly simple, but I have searched this site
I have searched for a general solution to this but only find answers to

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.