Validate date without datepicker?

I have a simple web form to collect subscribers birthdays. By default adding the field as a date field seems to be problematic, since on mobile is opens a date picker (which is a PITA, and unnecessary, to enter a birthday).

I’d like to find a way to let the user enter the date into MM-DD-YYYY but convert it to ISO8601 on submti, with no datepicker being used at all.

is there a good way to do this?


I would add a “pattern” attribute:

<input type="date" name="bday" required pattern="\d{2}-\d{2}-\d{4}">

Then after submission, validate with a PHP REGEX and convert the posted date to ISO8601

if (preg_match('`\d{2}-\d{2}-\d{4}`', $_POST['bday'])) {
    $iso = preg_replace('`(\d{2})-(\d{2})-(\d{4})`', '$3-$2-$1', $_POST['bday']);
} // not tested, but this is the idea
1 Like

You can do it like most other websites. Make a separate select for day month and year.

1 Like

Use <input type=“text”

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.