Expand my Community achievements bar.

SOLVED

How to mask SSN?

Avatar

Level 2

I want to be able to mask a SSN that is displayed on a Form. For example, the user would enter nine digits for the SSN, but when displaying on the form and for printing purposes the field gets masked as ***-**-9999 for security purposes. When saving the SSN to the database the entire nine digits are captured.

I tried to manipulate the Validation Pattern in the Display tab for that object to something like text{***-**-9999}, but nothing seems to work there. Has anyone else tried to do something similar? Any help is appreciated.

Thanks,

Mike

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Hi Mike,

Patterns aren't intended to perform this kind of character replacement. Here is some code that will do the trick - the only catch is you will have to add a hidden field to hold the SSN for binding.

I created 2 fields, form1.page1.subform1.ssnMasked and form1.page1.subform1.ssn. The exit script on ssnMasked is as follows:

// form1.page1.subform1.ssnMasked::exit - (JavaScript, client)

if (form1.page1.subform1.ssnMasked.rawValue != null) {

  var ssn = form1.page1.subform1.ssnMasked.rawValue;

  var regExp = /^(\d{9}|\d{3}-\d{2}-\d{4})$/;

  if (regExp.test(ssn)) {

    regExp = /^\d{9}/;

    if (regExp.test(ssn)) {

      this.rawValue = "***-**-" + ssn.substring(5,9);

      form1.page1.subform1.ssn.rawValue = ssn;

    }

    else {

        this.rawValue = "***-**-" + ssn.substring(7,11);

        ssn = ssn.substring(0,3) + ssn.substring(4,6) + ssn.substring(7,11);

        form1.page1.subform1.ssn.rawValue = ssn;

    }

}

else {

  xfa.host.messageBox("SSN must be in the form 123-45-6789 or 123456789.","SSN Error",0,0);

  xfa.host.setFocus("form1.page1.subform1.ssnMasked");

  }

}

You can enter the SSN in form1.page1.subform1.ssnMasked as 123-45-6789 and 123456789, otherwise validation fails. If validation passes, both fields are re-constructed accordingly. The field for binding, form1.page1.subform1.ssn, will be in the format 123456789.

Steve

View solution in original post

3 Replies

Avatar

Correct answer by
Former Community Member

Hi Mike,

Patterns aren't intended to perform this kind of character replacement. Here is some code that will do the trick - the only catch is you will have to add a hidden field to hold the SSN for binding.

I created 2 fields, form1.page1.subform1.ssnMasked and form1.page1.subform1.ssn. The exit script on ssnMasked is as follows:

// form1.page1.subform1.ssnMasked::exit - (JavaScript, client)

if (form1.page1.subform1.ssnMasked.rawValue != null) {

  var ssn = form1.page1.subform1.ssnMasked.rawValue;

  var regExp = /^(\d{9}|\d{3}-\d{2}-\d{4})$/;

  if (regExp.test(ssn)) {

    regExp = /^\d{9}/;

    if (regExp.test(ssn)) {

      this.rawValue = "***-**-" + ssn.substring(5,9);

      form1.page1.subform1.ssn.rawValue = ssn;

    }

    else {

        this.rawValue = "***-**-" + ssn.substring(7,11);

        ssn = ssn.substring(0,3) + ssn.substring(4,6) + ssn.substring(7,11);

        form1.page1.subform1.ssn.rawValue = ssn;

    }

}

else {

  xfa.host.messageBox("SSN must be in the form 123-45-6789 or 123456789.","SSN Error",0,0);

  xfa.host.setFocus("form1.page1.subform1.ssnMasked");

  }

}

You can enter the SSN in form1.page1.subform1.ssnMasked as 123-45-6789 and 123456789, otherwise validation fails. If validation passes, both fields are re-constructed accordingly. The field for binding, form1.page1.subform1.ssn, will be in the format 123456789.

Steve

Avatar

Level 2

Hi Steve,

Thanks for the response! This works like a charm and is exactly what I am looking for.

Regards,

Mike

Avatar

Level 1

I'm trying to create a java script that will show all digits if a check box is checked but mask the first 5 digits if the box is unchecked.  Is this even possible?

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----