Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
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".
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
I would place it in the "on blur" action of the field you entering the SSN into.
Copy link to clipboard
Copied
Again, thank you for the help. I understand now how to create an "on Blur" action. However, I am still unclear on where the names of the two field names are in the javascript (source field and destination field). I have tried to figure it out but can't get it to work.
Could you please point out where in the code the source and destination form field names are? Or even better: would you mind posting the correct code with my form field names? They are "SSN" and "Last4SSN". Thanks!
Copy link to clipboard
Copied
The field into which the full SSN is entered within the script is the "event" object and the contents of the field is "event.value"
The field which will be updated with only the last 4 of the SSN is named "SSN2" in the example. You can change that name as needed to match your form. So you would only need to change the "SSN2" to "Last4SSN".
Copy link to clipboard
Copied
My source field is named "SSN"
My destination field is named "Last4SSN"
Is this the correct code (it's not currently working for me)?
//On blur action to copy last 4 of SSN to another field;
var cResultField = "Last4SSN"; // 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;
Copy link to clipboard
Copied
Might be, but it's unnecessarily complicated.
Just use this as the custom calculation script of Last4SSN:
event.value = this.getField("SSN").substr(-4);
Find more inspiration, events, and resources on the new Adobe Community
Explore Now