We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Date field to not allow any characters or numbers in the record producers

ChanduM
Tera Contributor

Hello Everyone, 

 

I have a date field where I don't want to allow the date field to enter any characters or numbers in the record producer. Can anyone help me in achieving this. 

1 REPLY 1

Namrata Ghorpad
Mega Sage

Hello @ChanduM ,

 

You can write the onChange Client script like below and select the field as date field.

function onChange(control, oldValue, newValue, isLoading) {


    if (isLoading || newValue == '') {


          return;


    }


  if (oldValue == newValue) {


  return;


  }



  g_form.hideFieldMsg('variable_name');



  if (!validate(newValue)) {


  g_form.showFieldMsg('variable_name','Not a valid date.','error');


  g_form.setValue('variable_name', '');


  }  


}




function validate(value) {


  if(!value)


  return true;





  if(typeof g_user_date_format !== 'undefined')


  return isDate(value, g_user_date_format);


  return parseDate(value) !== null;


}

 

Please mark my answer as helpful or correct if it helps to resolve your issue.

Regards,

Namrata