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.

Service Catalog accepts only alphanumeric values

mano9335
Kilo Contributor

I need a client script that accepts alphanumeric, excluding special characters and 'na' 'n/a' 'None'. I have single line text box to that field. Please anyone help me with this.

Thanks

17 REPLIES 17

Hi Tom,



Is there any possibility to create a macro. I have multiple fields that need this functionality. Please Advise.


You can declare function in onLoad client script and access in onChange client script.


Hi Chuck,



I am facing the following problem with the script-



find_real_file.png



Please help.


chirag_bagdai
ServiceNow Employee
ServiceNow Employee

Hi Asit,



Can you please try below script:



Declare isAllLetter function in onLoad client script and call this function in onChange client script :



function onLoad() {


    //Type appropriate comment here, and begin script below


   


}


function isAllLetter(inputtxt)


{


  var letters = /^[a-zA-Z0-9]*$/;


  if(inputtxt.toLowerCase() !='na' && inputtxt.toLowerCase() !='n/a' && inputtxt.toLowerCase() !='none' && inputtxt.match(letters))


  return true;


  else


  return false;


}



onChange Client script:


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


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


  return;


  }


  g_form.hideFieldMsg('fieldName');



  if(!isAllLetter(newValue.trim()))


            g_form.showFieldMsg('fieldName', 'Invalid input', 'error');


  else


            g_form.hideFieldMsg('fieldName');


}


or you can directly use function script in your onChange client.