How to make a single line text variable in service catalog to accept only numerical values

andrewdevadhas
Kilo Contributor

Hi SNOW users,

I have a Service catalog form with a single line text variable. I need to make it to accept only numerical values. 

Is there any similar validation properties available for any of the variables in service catalog

1 ACCEPTED SOLUTION

Pothuraju
Mega Expert

HI Andrew,

Have a look.

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var number = g_form.getIntValue('u_quantity');
//if "Not a Number", clear the number value
if (isNaN(number)){
//number = "";
g_form.setValue('u_quantity','');
g_form.showFieldMsg('u_quantity','Please enter a valid integer number - stripping out non-numeric characters','info');

}

}

View solution in original post

6 REPLIES 6

Simon Christens
Kilo Sage

You can by making the client script run as an onChange script on this specific field.

 

As the others have said.

if (isNaN(newValue) || !isFinite(newValue) || newValue.indexOf('.') > -1) { //This if you only want whole numbers newValue.indexOf('.') > -1

g_form.showFieldMsg('field_name','Not a number','error');
}

andrewdevadhas
Kilo Contributor

Thanks every one it all worked. 

thanks..