Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Validation on Catalog item Variable?

micky09
Tera Contributor

I need to a validation on a catalog item field, Filed type is String, validation should be that it will not allow any spaces, special characters can be included but spaces are not allowed.

3 REPLIES 3

Jaspal Singh
Mega Patron
Mega Patron

Hi Micky,

 

You can use an onChange() client script that for the string field with below code.

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

   if (isLoading || newValue === '') {
   return;
   }
   var regex = new RegExp("^[a-zA-Z0-9]*$");
   if(!regex.test(newValue)){
   alert('Avoid using Spaces & Special characters.');
   g_form.setValue('yourvariablefielname','');
   }

}

Anil Shewale
Mega Guru

Hi micky09

var pattern =/^[A-Za-z'"_](\S)*$/;

/^[a-zA-Z'"-](\S)*$/

var name = g_form.getValue('updated_first_name');
if (!pattern.test(name)){


g_form.addErrorMessage("Only Characters are allowed");
g_form.setValue('updated_first_name','');

}

https://community.servicenow.com/community?id=community_question&sys_id=0c86f006db9be7409540e15b8a96...

 

If it help mark helpful or correct.

Thanks and regards

Anil

Pratiksha Kalam
Kilo Sage

Hello,

This is very useful article to solve your requirement.

https://community.servicenow.com/community?id=community_article&sys_id=78785137dbcbf3801cd8a345ca961...

Also ,

https://community.servicenow.com/community?id=community_question&sys_id=edbf928bdb916bc0fb115583ca96...

 

If answer is helpful please mark correct or helpful!

Thanks,

Pratiksha