Skip to main content
Participant
May 17, 2017
Question

Last four ssn

  • May 17, 2017
  • 2 replies
  • 3290 views

Does anyone know the JavaScript which will allow me to input the entire SSN in one field and have it copy just the last four into another field in the document?  Thanks for the help!

This topic has been closed for replies.

2 replies

Inspiring
May 17, 2017

It should be noted that the validation for the special SSN format does not exclude values where the first 3 digits, region, are "000" or "666" which values are not used in issuing SSNs. Also the last 4 digits, serial number, cannot be "0000".

akperioAuthor
Participant
May 25, 2017

I'm sorry but I'm not totally clear on your post. Should I copy your script and paste it into the "Custom Calculation Script" box on the full SSN form field?

Where exactly do I have to insert the names of both my source (full SSN) field and destination (last 4) field?

Thanks!

Inspiring
May 25, 2017

I would place it in the "on blur" action of the field you entering the SSN into.

Inspiring
May 17, 2017

Since the entry of the SSN could include the separator characters "-", ".", " ", or none one cannot easily use the substr or substring properties of a string unless all possible combinations of the numbers and special characters are teste. Fortunately JavaScript has implemented the Regular Expression object so one can test the inputted string and retrieve only the numeric digits.

The following script used in the on blur action can copy the last 4 digits of the SSN from the input field to a second field. You will need to adjust the field name to match your form.

// 0n blur action to copy last 4 of SSN to another field;

var cResultField = "SSN2"; // name of other field;

if(event.value != "")

{

// use Regular Expression object to extract last 4 digits of SSN ignoring any separator characters;

if(/^(\d{3})[-. ](\d{2})[-. ](\d{4})$/.test(event.value))

{

  this.getField(cResultField).value = RegExp.$3;

} // end if RegExp test true;

} // end event value not null;

// end on blur action;