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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:54:31+00:00 2026-05-20T08:54:31+00:00

i need to enter mobile number in a text field. i need to display

  • 0

i need to enter mobile number in a text field.

i need to display mobile number like this format 123-456-7890.

for eg: 1234567890 is my mobile number,while am entering this mobile number in text field,

for first 3 digits i need to place -,after 3 digits again i need to place -.

if i enter 123 then automatically place – in text field,after 456 place ,no need of placing for further 4 digits.

similar to displaying text in currency format.

but while getting text from that text field i need to get mobile number no need of – like 1234567890,not 123-456-7890.

i think my question is quite clear now,let me add comment if is not.

Thank u 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-20T08:54:32+00:00Added an answer on May 20, 2026 at 8:54 am

    Just to clarify: As a user enters a phone number into a UITextField, you would like it to automatically insert dashes in the proper places.

    The answer is in using the UITextFieldDelegate protocol.

    1) Set your controller object as a delegate for the UITextField.

    2) You’ll find the following method in the protocol:

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

    This method is called every time a character change occurs in the text field.

    3) How robust you want your implementation to be is up to you. You could simply do a count of the current characters and insert dashes after 3 and 6 characters. It would be wise to also reject any non-numeric characters.

    Here is a sample implementation. We basically take over the field editing manually – Inserting dashes after the appropriate string lengths and making sure the user can only enter numbers:

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
        NSCharacterSet *numSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789-"];
        NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
        int charCount = [newString length];
    
        if ([newString rangeOfCharacterFromSet:[numSet invertedSet]].location != NSNotFound
            || [string rangeOfString:@"-"].location != NSNotFound
            || charCount > 12) {
            return NO;
        }
    
        if (charCount == 3 || charCount == 7) {
            newString = [newString stringByAppendingString:@"-"];
        }
    
        textField.text = newString;
    
        return NO;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I often need to enter text (consisting of repeated characters) like this: ------------------------------------ TODO
I have a requirement where i need to enter a text in the text
I had two fields some thing like phone number and mobile number. Some thing
I'm coding a new website that will need users to enter their mobile phone
I need help from you all in Android mobile number verification process. I have
i need to enter a string to my database, this string may contain this
I need to make the Enter key as Tab, changing the focus of the
I need a form to enable user to enter event info in three fields
I need to implement a functionality to allow users to enter price in any
I need a component that will allow me to enter a signature on 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.