How do I shorten the length of my field and only allow numeric characters

Cupcake
Mega Guru

I have a field on a catalog form. The field is requesting the last four digits of the SSN # or Personal ID #. Today the field is setup as a single line text field, but I want to do the following:

a) make the field size = 4

b) I only want to allow that field to have numeric characters

find_real_file.png

I want to ensure that when I shorten the field size that I am only shortening it for this variable.

Thanks,

Karen

1 ACCEPTED SOLUTION

My apologies. Try changing it to /^[0-9][0-9][0-9][0-9]$/ inside the quotes.


View solution in original post

16 REPLIES 16

Brad Tilton
ServiceNow Employee
ServiceNow Employee

I think you would need to run an onchange client script on the field to make sure that there are not more than 4 digits and they're all numbers.


joshua_bice
Giga Expert

Two things to do:



1. In the attributes field of the variable, add max_length=4
2. Create an onChange client script for the field with the following code:



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


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


                  return;


        }


        var check = new RegExp('\d\d\d\d');



        if(!check.test(newValue)){


                  alert('Please enter a valid PIN or Last Four'); //The wording can be modified, of course.


                  control.value = oldValue;


        }



}


Joshua I wanted to say thank I haven't tried this yet but when i do I will mark it correct answer or helpful. I will not forget.


Joshua two things:


a) the max_length = 4 is working perfectly


b) I am getting a bad escapement error on the client script



find_real_file.png