date validation in servicenow
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == oldValue) {
return;
}
if (getDateFromFormat(newValue, 'dd-MM-yyyy HH:mm:ss') == 0) {
g_form.hideErrorBox('pstart_date');
g_form.showErrorBox('pstart_date', 'Date is invalid');
}
else {
g_form.hideErrorBox('pstart_date');
}
}
// client script
function onSubmit() {
if (getDateFromFormat(g_form.getValue('pstart_date'), 'dd-MM-yyyy HH:mm:ss') == 0) {
return false; // Prevents the form from submitting
}
if (getDateFromFormat(g_form.getValue('pend_date'), 'dd-MM-yyyy HH:mm:ss') == 0) {
return false; // Prevents the form from submitting
}
if (getDateFromFormat(g_form.getValue('other_field'), 'dd-MM-yyyy HH:mm:ss') == 0) {
return false; // Prevents the form from submitting
}
}