Regular js for HH: MM time from 00:00 to 23:59
3 answers
^(?:0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$ Details:
^- beginning of line(?:- the beginning of a non-seizing group0[0-9]|1[0-9]|2[0-3]- exciting trappings)- end of non-capturing group:- colon character (separating hours and minutes)[0-5]- an exciting submask of the number from 0 to 5[0-9]- exciting submask of numbers from 0 to 9
$- end of line
|
If there are other data in addition to time in the line, then this regular schedule is more suitable.
/(([2][0-3])|([0-1][0-9])):([0-5][0-9])/ For example -
console.log("bla-bla 23:17 bla-bla".replace(/(([2][0-3])|([0-1][0-9])):([0-5][0-9])/,'zzz')) |
^([01]\d|2[0-3]):([0-5]\d)$ Format from 00:00 to 23:59
/^([01]\d|2[0-3]):([0-5]\d)$/.test('22:10') // истина /^([01]\d|2[0-3]):([0-5]\d)$/.test('Бла 22:10 бла') // ложь |
/\d{2}:\d{2}/- user210322