Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

242
Views
How to validation time 12 hour for onTextChange at TextInput in React-Native

I have a TextInput and its placeholder in 12 hours (00:00) format with no AM or PM suffix, and I want when the user finishes typing the time, it automatically adds a ':' character after I enter the hours time. then I keep entering the number of minutes, and while the user enters the number of hours greater than 12, it automatically converts the hour to the 12-hour format, for example, if the user enters 13 it should automatically change back to 01 and then add the character ':' after.

Ex: 02 -> 02:xx,

15 -> 03:xx

Below is my code


const [times, setTime] = useState('');

const convertTime12Hours = (time12h) => {
    const time = time12h.split(' ');

    let [hours, minutes] = time.split(':');

    if (hours >= '12') {
        hours = hours % 12;
    }
    setTime(`${hours}:${minutes}`);
};

<TextInput
    value={times}
    style={styles.text_input}
    onChangeText={(value) => {
        convertTime12Hours(value);
    }}
    placeholder='00:00'
/>;

Please, Hope you guys can help me.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!