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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:34:35+00:00 2026-05-14T19:34:35+00:00

Whats the best way to ensure the user has entered a valid time string

  • 0

Whats the best way to ensure the user has entered a valid time string such as:

5:24
5.4

102:30
102.5

It will be entered into a UITextField therefore will be in a NSString.

I want to allow the user to enter the time in either hours and minutes (hh:mm) or hours and decimal minutes (hh.m).

In the hours minutes example they should be able to enter as many hours as the like but only between 0 – 59 minutes. With the hours decimal minutes I want them to only be able to enter again as many hours as the like but decimal minutes can only be 0 – 9.

Many Thanks

  • 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-14T19:34:35+00:00Added an answer on May 14, 2026 at 7:34 pm

    If you are using the latest non beta SDK (3.2), you can use regular expressions for this.

    NSString *myString = @"5:24";
    NSString *myRegex = @"^\\d+(?:[:](?:[0-5]?\\d)|\\.\\d)$";
    NSRange myRange = [myString rangeOfString:myRegex options:NSRegularExpressionSearch];
    if (myRange.location != NSNotFound)
      // the string is valid
    else
      // the string is invalid
    

    Matches:

    5:12
    5:1
    5:01
    5:0
    5:00
    1234567:12
    0:0
    5.1
    5.0
    0.1
    0.0
    1234567.1
    

    Non-matches:

    5     // symbol required (i.e. ":" or ".")
    5:    // minutes are required
    5:123 // too many minutes, max is 2 digits
    5:67  // minutes can only be up to 59
    -5:12 // negative numbers aren't allowed
    5.    // minutes are required
    5.12  // too many minutes, max is 1 digit
    :12   // hours are required
    .12   // hours are required
    5.1a  // string must not contain "a"
     5.1  // string must not contain whitespace " "
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whats the best way to separate the string, Parisi, Kenneth into Kenneth and Parisi?
Whats the best way to implement rollover 'buttons' like Stackoverflow has for 'Questions', 'Tags',
Whats the best way to ensure that only CRON executes PHP scripts, and not
Summary What's the best way to ensure a table cell cannot be less than
What is the best way to ensure service robustness to prevent a service becoming
In an environment with multiple windows servers what is the best way to ensure
Whats the best way to detect collisions in a 2d game sprites? I am
Whats the best way to round in VBA Access? My current method utilizes the
whats the best way to export a Datagrid to excel? I have no experience
So, in your experience, whats the best way? Is there a secure way that's

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.