We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Restrict single line text variable limit to 40 number

Radhe
Tera Expert

Hello All,

I am trying to restrict single line text variable limit to 40 numbers with the help of RegEX (^[1-4]?[0]$|^[1-3]?[0-9]$)

like field will not accept any character and it will receive only digit minimum 1 hours and maximum 40 hours.

find_real_file.png

1 ACCEPTED SOLUTION

Dhananjay Pawar
Kilo Sage

Hi,

Correct me if I am wrong.

What you need is Variable value should between 1-40 not 40 lengths value.

If yes then have onChange client script on that variable.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}

var val=g_form.getValue('variable name'); //enter correct variable name

if(val<0 && val>40){

g_form.setValue('variable name',''); //enter correct variable name

}

}

Thanks,

Dhananjay.

View solution in original post

16 REPLIES 16

AlpUtkuM
Mega Sage
    var dig = g_form.getValue('your_variable_name');

    if (dig.toString().length > 40) {

        g_form.clearValue('your_variable_name');

        g_form.showFieldMsg('your_variable_name', 'Please enter 40 digits', 'info');

You could write above client script to prevent users to input more than 40 digits(chars)

Dhananjay Pawar
Kilo Sage

Hi Radhe,

Do we need follow-up on this?

If this has resolved kindly mark appropriate response as correct and close the thread so others will refer same in future.

Thanks,

Dhananjay.