How to set the limit in a integer field value

utkarsh6
Giga Contributor

Hi All,

I have a question how to put the limit on any integer field. Like in a field we only put the integer value but I also want to specify that field like user can only enter min 5 digit or max 7 digit numeric value. I have already written the On-change catalog client script for only entering the integer value but also want to limit the number of digits.

 

Request you to please help or guide.

 

Thanks/Utkarsh

7 REPLIES 7

Utpal Dutta1
Mega Guru

Hey Utkash,

 

Try this onChange Client Script on your Field (Select the field 1st):

 

 

if(newValue.length > 7){

 

alert('yes');

 

}

 

else{

alert('no');

}

}

 

Modify the script according to your need. If it works then please mark my answer Correct and Helpful.

 

 

Thanks and Regards:

Utpal Dutta

It worked on me, thanks

 

Suseela Peddise
Kilo Sage

Hi,

You can use length to determine the number of digits.

Ex: 

var len= g_form.getValue('<<fieldname>>').length;  //replace with variable name

if(len<5)

{

alert('Number should be at least 5 digits in length');
g_form.setValue('<<fieldname>>',''); //replace with variable name

}

else if(len >7) 
{
alert('Number should not exceed 7 digits in length');
g_form.setValue('<<fieldname>>',''); //replace with variable name

}

 

If I have answered your question, please mark my response as correct and/or helpful.

Thanks,

Suseela P.

Thousif S N2
Tera Contributor

Go to below link:

 

https://community.servicenow.com/community?id=community_question&sys_id=5af347e5dbd8dbc01dcaf3231f96...

 

 

If it works then please mark my answer Correct and Helpful

 

Thanks and Regards:

Thousif