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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:46:31+00:00 2026-05-26T01:46:31+00:00

I am using UITextField and i want that should take character in the format

  • 0

I am using UITextField and i want that should take character in the format of xx-xx-xxx only numbers.

any help ?

  • 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-26T01:46:31+00:00Added an answer on May 26, 2026 at 1:46 am

    Try below it will work

    Objective-C

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
    {
        int groupingSize = 2;
        if([string length] == 0) {
            groupingSize = 4;
        }
        NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init] ;
        NSString *separator = @"-";
        [formatter setGroupingSeparator:separator];
        [formatter setGroupingSize:groupingSize];
        [formatter setUsesGroupingSeparator:YES];
        [formatter setSecondaryGroupingSize:2];
        if (![string  isEqual: @""] && (textField.text != nil && textField.text.length > 0)) {
            NSString *num = textField.text;
            num = [num stringByReplacingOccurrencesOfString:separator withString:@""];
            NSString *str = [formatter stringFromNumber:[NSNumber numberWithDouble:[num doubleValue]]];
            textField.text = str;
        }
        return YES;
    }
    

    Swift-3

    extension ViewController: UITextFieldDelegate {
    
        func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
            var groupSize = 2
            let separator = "-"
            if string.characters.count == 0 {
                groupSize = 4
            }
            let formatter = NumberFormatter()
            formatter.groupingSeparator = separator
            formatter.groupingSize = groupSize
            formatter.usesGroupingSeparator = true
            formatter.secondaryGroupingSize = 2
            if var number = textField.text, string != "" {
                number = number.replacingOccurrences(of: separator, with: "")
                if let doubleVal = Double(number) {
                    let requiredString = formatter.string(from: NSNumber.init(value: doubleVal))
                    textField.text = requiredString
                }
    
            }
            return true
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using RegexKitLite, i want to validate that my uitextfield has + prefixed
Possible Duplicate: Iphone UITextField only integer I want to place a text field that
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Scenario: I have 4 UITextFields that only accept 1 character. Easy. Problem: After I
I'm using a UITextfield to input information. I have several UITextfields that need to
Is there any way to do this? What I really want is a UITextField
I have a UITextField that I want to display a pre-defined list of email
i am using a UITextField with multilines and want to add line specing as
Hey I am using a UITextField to take float value inputs. I am facing
Hey guys , I am using a Numbers & Punctuation Keypad for the UITextfield

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.