Last active
May 1, 2018 12:40
-
-
Save kutyel/61e1e3ff12605d21bea1 to your computer and use it in GitHub Desktop.
AngularJS filter to format IBAN accounts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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