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

221
Views
Input date validation while typing the date yyyy-mm-dd format

I am trying to block the user to enter invalid numbers. I am currently supporting the years from 1901 to 20XX. So for example when the user is trying to enter the year from either 2 or 1 should be fine in the first letter but not 3. In the second character, a user can enter 9 or 0 and they shouldn't enter 3 or 4, etc. this is my current implementation but it's blocking from the first character because it's checking for the entire string at once.

                   <TextField
                    fullWidth
                    sx={{ pr: 3 }}
                    value={dateOfBirth}
                    {...params}
                    onInput={(e) => {
                      const regex =
                        /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$/;
                      console.log(e.target.value);
                      e.target.value = regex.test(e.target.value)
                        ? e.target.value
                        : "";
                    }}
                 
                  />
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!