1

I am developing a web application in which I have multiple HTML fields of type datetime-local. Users should provide the value for this in the following format:

2022-04-01T14:44:53

Since it is a user-selectable field sometimes users are omitting final seconds for this field. Date time with missing seconds value:

2022-04-01T14:44:53 //missing final seconds :53

Is there any way I can validate the same in JavaScript? I am developing the application using Nuxtjs/Vuejs. Better if there is any way I can add the validation within my HTML element itself.

Following is my HTML element:

<input
v-model="specificDateTime"
type="datetime-local"
class="form-control"
title="Set Event Time"
value="2022-04-01T10:00:00"
step="1"
>

Please let me know if there is any possibility to validate datetime-local at the HTML level itself based on the format. If not how can I do the same in my JavaScript?

If I provide empty values to hour/minutes then I get the error message but if I make the seconds as empty then I do not get the error. How to make the seconds field to be required so if the user provide empty values then it should throw the error.

BATMAN_2008
  • 2,788
  • 3
  • 31
  • 98
  • [*How to validate a date?*](https://stackoverflow.com/questions/5812220/how-to-validate-a-date) – RobG Apr 05 '22 at 13:54

0 Answers0