I need help with Javascript. I need to replace however many characters there are previous to the last 4 digits of a text field that contains bank account number. I have searched through the net on this, but cannot find one code that works. I did find a code here on stackoverflow, which was regarding credit card,
new String('x', creditCard.Length - 4) + creditCard.Substring(creditCard.Length - 4);
I just replaced the creditCard with accounNumObject:
var accounNumObject = document.getElementById("bankAcctNum")
The input is pretty simple.
<cfinput type="text" name="bankAcctNum" id="bankAcctNum" maxlength="25" size="25" value="#value#" onblur="hideAccountNum();">
Can anyone help please?
To replace a string with
xexcept for the last four characters in JavaScript, you could use (assumingstrholds the string)…jsFiddle.
You could also use a regular expression…
If you want to add the
4from a variable, construct the regex with theRegExpconstructor.jsFiddle.
If you’re fortunate enough to have the support, also…
Polyfill for
String.prototype.repeat()is available.