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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:42:41+00:00 2026-06-07T17:42:41+00:00

I have a simple app that helps recruiters collect information while at an event.

  • 0

I have a simple app that helps recruiters collect information while at an event. One form field was for a phone number, and I wanted a simple way to reformat the phone number as the user types.

The phone number should evolve as the user types, so sample output for a string of numbers should look like this:

1
1 (20)
1 (206) 55
1 (206) 555-55
1 (206) 555-5555

Or alternatively, if the user didn’t enter a 1 before the area code, the phone number would evolve like this:

(20)
(206) 55
(206) 555-55
(206) 555-5555

If the phone number is too long, then it should just show a plain string of numbers:

20655555555555555
  • 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-07T17:42:42+00:00Added an answer on June 7, 2026 at 5:42 pm

    Here’s what I did: the UITextFieldDelegate handles the textField:shouldChangeCharactersInRange :replacementString: method by getting the text of the UITextField, and running a little method that I wrote:

    -(void)updatePhoneNumberWithString:(NSString *)string {
    
        NSMutableString *finalString = [NSMutableString new];
        NSMutableString *workingPhoneString = [NSMutableString stringWithString:string];
    
        if (workingPhoneString.length > 0) {
        //This if statement prevents errors when the user deletes the last character in the textfield.
    
            if ([[workingPhoneString substringToIndex:1] isEqualToString:@"1"]) {
            //If the user typed a "1" as the first digit, then it's a prefix before the area code.
                [finalString appendString:@"1 "];
                [workingPhoneString replaceCharactersInRange:NSMakeRange(0, 1) withString:@""];
            }
    
            if (workingPhoneString.length < 3) {
            //If the user is dialing the area code...
                [finalString appendFormat:[NSString stringWithFormat:@"(%@)", workingPhoneString]];
    
            } else if (workingPhoneString.length < 6) {
            //If the user is dialing the 3 digits after the area code...
                [finalString appendFormat:[NSString stringWithFormat:@"(%@) %@", 
                                           [workingPhoneString substringWithRange:NSMakeRange(0, 3)], 
                                           [workingPhoneString substringFromIndex:3]]];
    
            } else if (workingPhoneString.length < 11) {
            //If the user is dialing the last 4 digits of the phone number...
                [finalString appendFormat:[NSString stringWithFormat:@"(%@) %@-%@", 
                                           [workingPhoneString substringWithRange:NSMakeRange(0, 3)], 
                                           [workingPhoneString substringWithRange:NSMakeRange(3, 3)],
                                           [workingPhoneString substringFromIndex:6]]];
            } else {
            //If the user's typed in a bunch of characters, then just show the full string.
                finalString = phoneString;
            }
    
            phoneNumberField.text = finalString;
        } else {
        //If the user changed the textfield to contain no text at all...
            phoneNumberField.text = @"";
        }
    
    }
    

    Hope this helps you!

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

Sidebar

Related Questions

I have one simple app that suppose to get information from user and send
I have a very simple webforms app that will allow field techs to order
I have a simple VB.NET 2008 app that helps users to edit fields in
Help me, Stackoverflow! I have a simple .NET 3.5 console app that reads some
This is a real newbie question. I have simple app that selects a picture
I have a simple app that will allow a user to tag a location.
Right so I have a simple app that consists of a calendar a Set
I'm now testing GKPeerPickerController. I have a simple app that just have a button
I have a simple catalogue app that lets users download product data from an
I have a simple PHP app that prints 'hello world'. When I run it

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.