Reputation: 1135
I have this input field
<input type="datetime-local" required>
I would like the date part to be always required, but not the time part... I tried with pattern, like
pattern="[0-9]{4}-[0-9]{2}-[0-9]{2}.*"
but it doesn't seem to work... any idea...
Edit: I explain better here
<form name="test" method="POST" action="/">
<input type="datetime-local" name="event_date_start" id="event_date_start"
min="2011-06-07T00:00"
max="2099-06-14T00:00" required><br>
<input type="submit"/>
What I want is to use datetime, but time must be optional. With the above example, submit is not allowed until you insert 00 in the time field..
I want to leave that optional...
Upvotes: 2
Views: 4389
Reputation: 36
No need for pattern just use the attributes min, max and value:
<input type="datetime-local"
value="2018-06-12T19:30"
min="2018-06-07T00:00"
max="2018-06-14T00:00" required>
If you want an inputfield with date only use:
<input type="date" required>
For time is optional:
<input type="date" required> <input type="time">
Upvotes: 2