I have reminders in the system, the client himself sets the date and time of the reminder, the time step in the selection field is 15 minutes. I use the calendar plugin, but users can enter 16:01 or 15:03, but it is necessary that I could enter the time in increments of 15 minutes, no more, no less.

Form field

<input name="end_time" id="end_time" type="text" /> 

js

 jQuery(function(){ jQuery('#end_time').datetimepicker({ lang:'ru', datepicker:false, format:'H:i', value:'<?=date('H'); ?>:00', step:15 }); }); 

How to do this?

  • I still do not understand what is not suitable for you 16:01 или 15:03 ? - Telion
  • because in reminders it is worth sending reminders once every 15 minutes. - Alexander Sizintsev
  • what datetimepicker are you using? Add a link to its documentation to the question - Grundy
  • one
    @AlexanderSizintsev, you can turn off the input editing, make a separate button that will change its value via js. - LEQADA

2 answers 2

Perhaps, so https://stackoverflow.com/a/15482666/873481 you only need to correctly select regexp (instead of / ^ \ d {3} $ /)

 $.validator.addMethod('minutesStep', function (value, element) { return this.optional(element) || /^\d{3}$/.test(value); }, "Please enter a valid phone number"); $(document).ready(function () { $("#end_time").validate({ rules: { field1: 'minutesStep' } }); }); 

Alternatively, http://w2ui.com/web/docs/form/fields-date

    Like this

    Time

     disabledTimeIntervals: [[moment({ h: 0 }), moment({ h: 8 })], [moment({ h: 18 }), moment({ h: 24 })]] 

    date

      $(function () { $('#datetimepicker5').datetimepicker({ defaultDate: "11/1/2013", disabledDates: [ moment("12/25/2013"), new Date(2013, 11 - 1, 21), "11/22/2013 00:53" ] }); }); 

    Steps and dock here http://eonasdan.imtqy.com/bootstrap-datetimepicker/Options/#stepping

    Dock Location http://prntscr.com/9gss2h

    • for 00:54 you propose to add a separate element? :) - Grundy