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

bernyalvarado
Mega Sage

Hi Manoj,



Are you familiar with regular expressions? You can accomplish this through regular expressions.



The following should be helpful:



javascript regex to validate alphanumeric text with spaces and reject special characters - Stack Ove...



Thanks,


Berny


Thanks for your response. I am new here and pretty not sure about scripting.



Thank you.


Hi Manoj,



You are welcome. If you are unfamiliar with scripting, check out developer.service-now.com. We also have courses available. In the mean time, consider parking some of these requirements that require scripting until you, or someone on your staff, can fully support them.


Chuck Tomasi
Tera Patron

Hi Kumar,



Your script would look something like this (assuming your field is not called yourField, adjust as needed)



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


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


  return;


  }


  g_form.hideFieldMsg('yourfField');



  var patt = "^[a-zA-Z0-9]*$";



  if (!patt.test(newValue))


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



  var patt2 = "^[Nn]/[Aa]$";



  if (!patt.test(newValue))


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



}