Skip to content

Instantly share code, notes, and snippets.

@webdados
Last active October 7, 2017 14:23
Show Gist options
  • Save webdados/19c8d4822b3a7ce27c31a1fc0e7d52f7 to your computer and use it in GitHub Desktop.
Save webdados/19c8d4822b3a7ce27c31a1fc0e7d52f7 to your computer and use it in GitHub Desktop.
Clean whitespaces from IBAN when pasting it on BPINet
//Add as many IBAN / NIB field IDs as you want
var ibanFields = [
"LT_BPINet_wt1_block_wtMainContent_CS_ClienteCanais_wt42_block_WebPatterns_wt581_block_wtContent_LT_BPI_Patterns_wtDadosBeneficiarioNacional_block_wtForm_LT_BPI_Patterns_wtRowIBAN_block_wtRow_LT_BPI_Patterns_wtIBAN_block_wtInput_wtTxtIBAN",
"LT_BPINet_wt20_block_wtMainContent_CS_Transferencias_wt12_block_wt3_WebPatterns_wt820_block_wtContent_LT_BPI_Patterns_wtfmFomularioDadosTranferencia_block_wtForm_LT_BPI_Patterns_wttxtIBAN_block_wtRow_LT_BPI_Patterns_wt652_block_wtInput_wttxtIBAN2",
"LT_BPINet_wt60_block_wtMainContent_CS_Transferencias_wt68_block_WebPatterns_wt273_block_wtContent_LT_BPI_Patterns_wt999_block_wtForm_LT_BPI_Patterns_wt442_block_wtRow_LT_BPI_Patterns_wt55_block_wtInput_wttxtContaIBANDestinatario"
];
//Add the event listener
for (var i = 0, len = ibanFields.length; i < len; i++) {
if ( el=document.getElementById(ibanFields[i]) ) el.addEventListener('paste', cleanIban);
}
//Clean it on paste!
function cleanIban(e) {
e.stopPropagation();
e.preventDefault();
var clipboardData = e.clipboardData || window.clipboardData;
var iban = clipboardData.getData('Text');
iban = iban.replace(/\s/g,'');
document.getElementById(this.id).value = iban;
}
@webdados
Copy link
Author

webdados commented Oct 7, 2017

This is quick and dirty. Can, and should, be improved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment