Search code examples
regexvalidationgoogle-sheetsconditional-statementsgoogle-sheets-formula

Data validation for time input in Google Sheets


I am searching for a solution that would allow users to insert time values only in this format: hh:mm, and reject if something else is inserted. Something similar like data validation for date - Data validation -> Is valid date -> Reject input.

I tried to search and adjust a Regexmatch formula for this one, with no success, but I am open for other suggestions also.

Thank you in advance!


Solution

  • SUGGESTION

    Perhaps you can try using a more specific regex such as the one sample from this existing post. Then, apply it your data validation via a custom function using REGEXMATCH function as seen here:

    =REGEXMATCH(TO_TEXT(A1),"^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$")

    Sample Data Validation Config:

    enter image description here

    Demo:

    E.g. Any text or date formats won't be accepted.

    enter image description here