How to validate a time input?

How to validate a time input?

nsaknsak Posts: 36Questions: 6Answers: 0

hi,

in the table I am building, one of the fields requests from the user to set a time and I need to validate it somehow. Specifically, I want the input to have the following format: 'hh:mm' (e.g. 05:45). Does Editor include a time validator, like it does for dates? If not how can I display the same error message, i.e. the one with the red letters that appears right under the input field, when the input is not valid?

Thanks!

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,765Questions: 1Answers: 10,111 Site admin
    Answer ✓

    With the Editor PHP libraries you should be able to use the dateFormat validator with a custom format:

                ->validator( 'Validate::dateFormat', array(
                        "format" => "H:i",
                        "message" => "Please enter a time in the format hh:mm"
                ) )
    

    Allan

  • nsaknsak Posts: 36Questions: 6Answers: 0

    Thanks!!

This discussion has been closed.