Skip to content

Instantly share code, notes, and snippets.

@kutyel
Last active May 1, 2018 12:40
Show Gist options
  • Save kutyel/61e1e3ff12605d21bea1 to your computer and use it in GitHub Desktop.
Save kutyel/61e1e3ff12605d21bea1 to your computer and use it in GitHub Desktop.
AngularJS filter to format IBAN accounts
(function() {
'use strict';
/**
* Formats a string and returns a valid IBAN account string
* @param {string} input example: 'ES0123456789012345678901'
* @return {string} output example: 'ES01 2345 6789 0123 4567 8901'
* @example <caption>{{'ES0123456789012345678901' | IBAN}}</caption>
*/
angular.module('app').filter('IBAN', () => iban => iban ? iban.replace(/[^\dA-Z]/g, '').replace(/(.{4})/g, '$1 ').trim() : '');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment