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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:30:57+00:00 2026-05-31T00:30:57+00:00

Maybe it’s a simple question but I can’t figure out the right way to

  • 0

Maybe it’s a simple question but I can’t figure out the right way to do it.

I have a UITextField. Since I need to validate the text that is inserted within this text field, I’m currently using the UITextFieldDelegate method - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string like the following:

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
   // do validation here
   // return YES or NO depending on previous validation
}

Since I have some text fields (they not belong to the same controller where the validation is performed) and I don’t want to duplicate text fields validation code, how can I achieve an elegant way to centralize a similar validation? I don’t know if subclassing is the right way, but in this case I need to use the same delegation method (the one listed above) in different parts of the same app.

Thank you 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-31T00:30:59+00:00Added an answer on May 31, 2026 at 12:30 am

    This depends on how much information your validation code requires. If the arguments of textField:shouldChangeCharactersInRange:replacementString: are all you need to determine whether to return YES or NO, then you can just use the same delegate for all your textFields.

    If you need to track and store information about previous validations in order to make validation decisions, the easiest way would be to package all that state up into an object, and have an array of those objects, each corresponding to a specific UITextField. Then, in textField:shouldChangeCharactersInRange:replacementString: you would use the state corresponding to the textField that was passed in.

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

Sidebar

Related Questions

Maybe this is a very simple question, but I just can not figure out.
Maybe I am out of my mind right now, but I have a question
Maybe I just can't figure out the right keywords to get an answer out
Maybe someone can help me out. I have created a simple web user control,
Maybe this is a poor question, but, I can't find a tutorial or even
Maybe this is a simple question, but I didn't find answer in web. I
Maybe this is very basic, but I am all confused. I have a simple
Maybe a silly question but here goes anyway. Example: Let's say I have one
Maybe my question is simple to solve for you, but I'm sitting here for
Maybe this is a dumb question, but is there any way to convert 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.