I am trying to make a date regex validator. The issue I'm having is that I'm using an input field with "date" type, which works like a charm in Chrome; it opens a calendar-like in Chrome, but in the rest it does nothing, so I decided to go for a manual input of the date for the rest.
This is my error throwing message (I'm looking for YYYY-MM-DD format):
$date_regex ='#^(19|20)\d\d[\- /.](0[1-9]|1[012])[\- /.](0[1-9]|[12][0-9]|3[01])$#';
$hiredate = $_POST['hiredate'];
if (!preg_match($date_regex, $hiredate)){
$errors[] = 'Your hire date entry does not match the YYYY-MM-DD required format.';
}
I know there are a lot of examples about this, but I tried like 20 already and I couldn't solve it. Maybe I'm missing something.
Here's the input field, if somewhat relevant:
<input type="date" name="hiredate" />
<input>boxes with an appropriate maxlength and digit-only validate which gets concatednated into the proper format on the backend? You can add listeners to each input box to go to the next one if a personkeypressed2 digits. The user doesn't give an rats behind about what format you need and you will only frustrate them at best if it is not their personal native formatIf insert fails then slap user in face...I would hope that a person knows not to go out of bounds in a date field or else you probably shouldn't hire them :)