24hrs time validation for string field

Eswar N1
Tera Contributor

In-Time and Out-Time must be between 00:00 to 23:59 format and Out-Time must be greater than In-Time

 

Refer attached img.

 

 

 

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;

var str = g_form.getValue('in_time');
var regex = new RegExp(/^\d?\d:\d{2}$/).test(str);

if (str == null) {
g_form.showFieldMsg('in_time', 'Please use the right format.', 'error');
return "false";
}

if (regex.test(str) == true) {
return "true";
} else {
return "false";
}
}
}

1 REPLY 1

OlaN
Giga Sage
Giga Sage

Hi,

Here is a regular expression that will cover the time validation,

your current one will allow for entering a time like "39:89"

^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$