Variable data validation

TheSonOfMogh
Kilo Contributor

Hey There Community!

Trying to do something that seems pretty straight forward but having a hard time finding the best mechanism to achieve this.

We have a requested item in our service catalog in which we'd like to do some data validation on.
When users fill out the variables in the form, one of them should require that it be a 15 digit number and not allow the user to proceed until that one field meets the requirements.

Hoping to get some feedback on what people have done to achieve a similar goal.


Thanks,

7 REPLIES 7

Abhinay Erra
Giga Sage

Mark,


       


You can write an onChange client script on the variable you want to validate and below script to check for any non digit characters and if the length is 15.


Note:You can also write an onSubmit to alert the error message and blank out the variable value if the conditions are not satisfied   and stop submitting the form



//'number_field' is my variable name


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


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


  return;


  }


  if(/\D/g.test(newValue)==false){


  if(newValue.length==15){


  }


  else{


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


  alert("Enter 15 digits");


  }


  }


  else{


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


  alert("Only digits allowed");


  }


}




Thanks,


Abhinay


Thanks so much for your reply, One question in regards to this.



One of the things i am trying to figure out is, when I create the client script, what table is it running against? Since it is a variable in the requested item, i assume it would be sc_req_item?


Mark,



  As far as I know, in catalog client scripts, table field does not matter at all. It applies to a specific catalog item.



Please mark this question as answered if my response has provided a resolution or if you need further assistance, please let me know




Thanks


Thanks!


You rock!!!