0

Regex date format YYYY-MM-dd

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
          return;
    }
  g_form.hideErrorBox('valid_date');
       var pattern =/([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))/;   // regex pattern
   if(!pattern.test(newValue)){
     g_form.showErrorBox('valid_date', getMessage('Please enter Valid Date'));//show error messege
           g_form.setValue('valid_date', '');
   }
}
Regex Validation to allow Valid Date YYYY-MM-dd format ServiceNow Client Script
Working Code Asked question July 24, 2023