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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:29:19+00:00 2026-06-05T16:29:19+00:00

I have an integer value that spans a range so large it is impractical

  • 0

I have an integer value that spans a range so large it is impractical to use a slider, as it lacks the sensitivity to pick out an exact value in that range.

I used a PSTextFieldSpecifier instead, and set the keyboard to Numbers. However, in Settings.app, the copy and paste function allows text to be inserted into what should be a numeric field.

Does anyone have a solution to the problem?

  • 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-05T16:29:21+00:00Added an answer on June 5, 2026 at 4:29 pm

    I have always implemented this with a custom

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

    routine. You monitor the characters as they come in and only accept the numerics.

    I used a UITextField, and implemented the UITextFieldDelegate methods outlined below:

    // This method enforces the textField to give up first responder and return
    -(BOOL)textFieldShouldReturn:(UITextField *)textField{
        [textField resignFirstResponder];
        return YES;
    }
    
    // This method copies the current UITextField' text into a string used for editing
    // comparing, and for if a cancelation occurs we can replace with the original text
    -(void)textFieldDidBeginEditing:(UITextField *)textField{
        initialValueWhenEntering = [NSString stringWithString:textField.text];
        [initialValueWhenEntering retain];
    }
    
    // This routine enforces that only a single period or numerics be taken into the new
    // value for the input
    -(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    
        unsigned int stringLength = (unsigned int)[textField.text lengthOfBytesUsingEncoding:NSASCIIStringEncoding];
        unsigned int counter;
        unsigned int periodCounter = 0;
    
        // Test to make sure there wasnt already some periods in the initial string
        for(counter = 0; counter < stringLength; counter++){
            if(   [textField.text characterAtIndex:(NSUInteger)counter] != '.' && 
                ( [textField.text characterAtIndex:(NSUInteger)counter] < '0' ||
                  [textField.text characterAtIndex:(NSUInteger)counter] > '9' ) ){
                return NO;
            }else if( [textField.text characterAtIndex:(NSUInteger)counter] == '.' ){
                periodCounter++;
            }
        }
    
        stringLength = (unsigned int)[string lengthOfBytesUsingEncoding:NSASCIIStringEncoding];
        for(counter = 0; counter < stringLength; counter++){
            if(   [string characterAtIndex:(NSUInteger)counter] != '.' && 
                ( [string characterAtIndex:(NSUInteger)counter] < '0' || [string characterAtIndex:(NSUInteger)counter] > '9' ) ){
                return NO;
            }else if( [string characterAtIndex:(NSUInteger)counter] == '.' ){
                periodCounter++;
            }
        }
    
        if( periodCounter <= 1 ){
            return YES;
        }else{
            return NO;
        }
    }
    

    And finally the routine that gets automatically called when the textfield has ended editing

    -(void)textFieldDidEndEditing:(UITextField *)textField{
        unsigned int stringLength = (unsigned int)[textField.text
                                    lengthOfBytesUsingEncoding:NSASCIIStringEncoding];
        unsigned int counter;
    
        if( 0 == stringLength ){
            textField.text = initialValueWhenEntering;
    
            float temperature = [textField.text floatValue];
    
            // Set the temperature of all element boxes
            for(counter = MIN_ELEMENT_INDEX; counter <= MAX_ELEMENT_INDEX; counter++){
                [periodicButtons[counter] setOutputType:myGraphType aValue:temperature];
            }
        }else if( 1 == stringLength ){
            if( [textField.text characterAtIndex:(NSUInteger)0] == '.' ){
                textField.text = initialValueWhenEntering;
            }
    
            float temperature = [textField.text floatValue];
    
            textField.text = [NSString stringWithFormat:@"%.2f", temperature];
    
            // Set the temperature of all element boxes
            for(counter = MIN_ELEMENT_INDEX; counter <= MAX_ELEMENT_INDEX; counter++){
                [periodicButtons[counter] setOutputType:myGraphType aValue:temperature];
            }
        }else{ // Should be a semi-valid number at this point
            float temperature = [textField.text floatValue];
    
            if( temperature > 5900.0 ){
                temperature = 5900.0;
            }
    
            textField.text = [NSString stringWithFormat:@"%.2f", temperature];
    
            // Set the temperature of all element boxes
            for(counter = MIN_ELEMENT_INDEX; counter <= MAX_ELEMENT_INDEX; counter++){
                [periodicButtons[counter] setOutputType:myGraphType aValue:temperature];
            }
        }
    
        [initialValueWhenEntering release];
    }
    

    In my example, I did perform value limit checking, but this code could be deleted.

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

Sidebar

Related Questions

I have a few integer keys that is needed to retrieve a value. What
Say I have an integer value that I output to a django template say
I have two columns in a table that are populated with integer values. For
I have a function h(n) that returns values for each integer 1 =< n
Using Spring 2.5 tag library, I have an Integer value in a command form
I have a fx1.15 notation. The underlying integer value is 63183 (register value). Now,
I have an Integer array, value[] . It may be of any length. I
I have an integer variable ( time ) in one view controller whose value
For example Dim aInt as Integer should have the value as nothing instead of
Let's say I have some_value = 23 I use the Integer 's times method

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.