Need to restrict a field to only 6 numeric digits

Conan_Lloyd
Mega Expert

I can't seem to figure out how to restrict the asset tag to only 8 numeric digits. Can I get a bit of help with the script?

6 REPLIES 6

Hello Bandita,



i really don't remember how I did for that; its been 3 years but to answer your question. I think you can give a try with the below catalog client script.


I think this will work.



Catalog client Script: OnChange



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


  try {



  if(isLoading) {


  return;


  }



  var cc = 'costcentre_field_name';


  var mymessage = getMessage('my msg');



  g_form.hideFieldMsg(cc, true);



  var validNb = new RegExp("^[0-9]*$");     //-Here 'RegExp' is used to check if the field contains only numeric



  if (!validNb.match(newValue) && newValue != '')   {


  g_form.setValue(cc,'');



  g_form.showFieldMsg(cc, mymessage, 'error');


  }



  } catch(exception) {


  // Specify the name of the Catalog Client Script in the log message


  jslog('Error in Catalog Client Script <Name of the Client Script>: ' + exception);


  }



}



Note : Here I have used a ui message to show the fieldMsg.



I hope this will solve your issue. Please let me know if it worked.



Thanks,


Chinthuja Johny


Conan_Lloyd
Mega Expert

Thank so much, it works like a charm