0
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
          return;
    }
  g_form.hideErrorBox('dup_record');
       var pattern =/(\b\w+\b)(?=.*\b\1\b)/;   // regex pattern
   if(pattern.test(newValue)){
     g_form.showErrorBox('dup_record', getMessage('Duplicate record found'));//show error messege
           g_form.setValue('dup_record', '');
   }
}
Regex to find Duplicate Records in a String Client Script ServiceNow
Working Code Edited question July 24, 2023