File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed
Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -84,6 +84,19 @@ export function isValidSwissIbanNumber(ibanNumber: string): boolean {
8484 return false ;
8585 }
8686
87+ /**
88+ * Validates a Swiss IBAN number.
89+ *
90+ * Steps:
91+ * - The number must start with `CH`, be 21 digits long and follow one of the accepted formats:
92+ * - `CHXX XXXX XXXX XXXX XXXX X`or `CHXXXXXXXXXXXXXXXXXXX`.
93+ * - Remove all whitespaces.
94+ * - Rearrange by moving the first 4 characters (CH + 2 check digits) to the end.
95+ * - Replace letters with numbers: A=10, B=11, ..., Z=35.
96+ * - Convert the resulting string to a large integer and calculate modulo 97.
97+ * - The number is valid if the resto of the calculation equals 1.
98+ */
99+
87100 const compactIbanNumber = ibanNumber . replaceAll ( " " , "" ) ;
88101 const rearrangedIban = compactIbanNumber . slice ( 4 ) + compactIbanNumber . slice ( 0 , 4 ) ;
89102 const numericStr = rearrangedIban . replaceAll ( / [ A - Z ] / g, ( ch ) => ( ch . codePointAt ( 0 ) ! - 55 ) . toString ( ) ) ;
You can’t perform that action at this time.
0 commit comments