The CreatorCon Call for Content is officially open! Get started here.

Limit for integer field

Sam Ogden
Tera Guru

Hi all,

I've used the below on change client script to inform users to enter values between 1 and 25.

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

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

          return;

        g_form.hideFieldMsg('u_risk_based_testing_score');

        var newVal = parseInt(newValue);
        if (newVal < 1 || newVal > 25) {
                  g_form.showFieldMsg('u_risk_based_testing_score', 'Values must be between 1 and 25', 'error');

        }

}

If I enter values 1 - 25 these are fine.   The error message then appears for values 26 - 999.

Then values 1,000 - 25,999 these do not show the error, then numbers 26,000 and above do.

Do you know what would cause this?

Alternatively is there a way to stop users adding more than 2 digits into the integer field?

What would I need to do to stop a user being able to save the form if they enter a value that is not between 1 and 25?

Thanks

Sam

18 REPLIES 18

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Sam,



Is it a integer field or string field since you are converting it into parseInt().


Why not use Regular expression for this?



Regards


Ankur


Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,



It is an integer field.   My understanding is all fields get seen as a string field and that is need to get it back to an integer?



Thanks



Sam


Hi Sam,



I think for number 1,000 the issue is coming up because of the comma. I think ServiceNow add comma if digit goes beyond 3.



Regards


Ankur


Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Is there a way to stop this?


Alternatively is there a way I can stop users adding more than 2 digits?