Copy link to clipboard
Copied
Hello,
Is there a script to display only the last 4 of a string of numbers where the full number of numerical characters can very?
Either display as "xxxx2298" or "2298". Or any other method.
Thanks,
Ed
In that case you can use this code as the field's custom calculation script:
event.value = this.getField("MEM_NMBR").valueAsString.substr(-4);
Copy link to clipboard
Copied
Sure. For example:
var fullString = "1234567890";
var lastFour = fullString.substr(-4);
Copy link to clipboard
Copied
Thanks for the reply try67,
I inserted this to the "custom calculation script" section but it didn't take. Assuming "1234567890" needs to be changed to my actual mapping (tag)?
Example correct?
Copy link to clipboard
Copied
The code I provided is generic, to show how it's done.
Are you copying the value from another field? If so, what's the name of that field?
Copy link to clipboard
Copied
I generally do copy from another (to be hidden) field. Where the hidden field name will be "MEM_NMBR".
Copy link to clipboard
Copied
In that case you can use this code as the field's custom calculation script:
event.value = this.getField("MEM_NMBR").valueAsString.substr(-4);
Copy link to clipboard
Copied
This worked. Thank you!
Copy link to clipboard
Copied
Try67, can you please help me flip this around to display the first 17 characters?
event.value = this.getField("MEM_NMBR").valueAsString.substr(-4);
-Ed
Copy link to clipboard
Copied
event.value = this.getField("MEM_NMBR").valueAsString.substr(0,17);
Copy link to clipboard
Copied
If I were to write the first question's solution to a more generalized form, I could change the number of last characters to display and compute the number of characters for the fill.
The code for the custom format could look like:
function DispalyLastNChars(nLength, cString)
{
var nRepeat = cString.length - nLength; // numbef of nod-display characters;
var cCover = "*".repeat(nRepeat); // string for non-display characters;
var cDisplay = cString.substr( nLength - nRepeat - 1, nLength); // stirng of characters to display;
return cCover + cDisplay; // displayed and non-displayed characters;
}
if(event.value != "")
{
event.value = DispalyLastNChars(4, event.value);
}
By changing the parameters for the "substr" method to start at the 0 character and go for the specified number of character and changing the order for combining the characters to display and hide, one could have:
function DispalyFirstNChars(nLength, cString)
{
var nRepeat = cString.length - nLength; // numbef of nod-display characters;
var cCover = "*".repeat(nRepeat); // string for non-display characters;
var cDisplay = cString.substr(0, nLength); // stirng of characters to display;
return cDisplay + cCover ; // displayed and non-displayed characters;
}
if(event.value != "")
{
event.value = DispalyFirstNChars(4, event.value);
}
You can read more about MDN JavaScript at JavaScript | MDN . "substr" is a method of the buitin "string" object.
Copy link to clipboard
Copied
Dear Try67,
How to masking the account number with “*” up to the last 4 digits in adobe forms.
Copy link to clipboard
Copied
See my post below or above. Here is the code and the location to place the code:
// custom format script;
if(event.value != "" && event.value.length > 4)
{
event.value = "*".repeat(event.value.length - 4) + event.value.substr(event.value.length - 4);
}
Copy link to clipboard
Copied
Hi gkaiseril,
Needed your help! how to execute the below process in formcalc or java script.
below the form created in adobe livecycle designer.
we have added no.of item in table,but the value and description all are cumulative in below table and sum the values.
Copy link to clipboard
Copied
Do you want to display only the last 4 with or without redacted leading positions/
You can have the form retain the full value of a field but only have that field display the last 4 digits. This is not the most secure approach since it is possible to still get to the full value of the field through JavaScript or some of the form tools.
The custom format script could be:
if(event.value != "" && event.value.length > 4)
{
event.value = "*".repeat(event.value.length - 4) + event.value.substr(event.value.length - 4);
}
You may need to create a custom keystroke script to limit the input to numbers only. The following script will limit keystrokes to numbers:
if(event.willCommit == false)
{
event.rc = /^\d*$/.test(event.change);
}
Copy link to clipboard
Copied
So many ways to skin a cat. Thank you. I made note of your suggestion. Totally makes sense.
-Ed