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

159
Views
How to allow only 2 digit numbers in html text input separated by colon?

How to allow only 2 digit numbers in html text input separated by colon?

Desired output 33:33

I tried this

<form name="form1"> 
 <input type="text"  name="pincode" maxlength="4"  id="pin" pattern="\d{4}" required/>
 <input type="Submit"/> 
</form>

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Your regex is wrong. try this:

<form name="form1"> 
 <input type="text"  name="pincode" maxlength="5" id="pin" pattern="\d{2}:\d{2}" required/>
 <input type="Submit"/> 
</form>

about 4 years ago · Santiago Trujillo Report

0

You can use regexp ^\d{2}:\d{2}$ which matches only strings of the form dd:dd, d representing a single digit.

input[name="pincode"]:invalid {
  background-color: red;
}

input[name="pincode"]:valid {
  background-color: green;
}
<form name="form1"> 
 <input type="text"  name="pincode" minlength="5" maxlength="5"  id="pin" pattern="^\d{2}:\d{2}$" required>
 <input type="Submit"> 
</form>

about 4 years ago · Santiago Trujillo Report
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!