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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:06:40+00:00 2026-05-27T00:06:40+00:00

I have a UITextField where user can enter a name and save it. But,

  • 0

I have a UITextField where user can enter a name and save it. But, user should not be allowed to enter blank spaces in the textFiled.

1 – How can I find out,if user has entered two blank spaces or complete blank spaces in the textFiled

2 – How can i know if the textFiled is filled only with blank spaces

edit – It is invalid to enter only white spaces(blank spaces)

  • 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-27T00:06:41+00:00Added an answer on May 27, 2026 at 12:06 am

    You can “trim” the text, that is remove all the whitespace at the start and end. If all that’s left is an empty string, then only whitespace (or nothing) was entered.

    NSString *rawString = [textField text];
    NSCharacterSet *whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet];
    NSString *trimmed = [rawString stringByTrimmingCharactersInSet:whitespace];
    if ([trimmed length] == 0) {
        // Text was empty or only whitespace.
    }
    

    If you want to check whether there is any whitespace (anywhere in the text), you can do it like this:

    NSRange range = [rawString rangeOfCharacterFromSet:whitespace];
    if (range.location != NSNotFound) {
        // There is whitespace.
    }
    

    If you want to prevent the user from entering whitespace at all, see @Hanon’s solution.

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

Sidebar

Related Questions

I have a UITextField but when it overflows I want it to scroll not
I have a UITextField but my users will prefer enter some number in that
Alright. Lets say i have a UITextField where a user can input an url
I have a strange problem. I have an UITextField in which the user should
In my iPhone app I have a settings page where a user can enter
I want to have a UISegmentedController but the user can choose the segment and
I have 6 UITextFields on my UIScrollView . Now, I can scroll by user
I have an app with a UITextField, amongst other things. When the user first
I have a UITextField with this NSNotification: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldDidChange:) name:@UITextFieldTextDidChangeNotification object:_searchTextField]; -
I have a bunch of UITextFields where a user must enter a number (the

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.