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
Solved! Go to Solution.
Views
Replies
Total Likes
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
Views
Replies
Total Likes
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
Views
Replies
Total Likes
Hi Steve,
Thanks for the response! This works like a charm and is exactly what I am looking for.
Regards,
Mike
Views
Replies
Total Likes
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?
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies