Implemented IBAN formatting to display with proper spacing: - Added formatIban() utility function in formatStrings.ts - Format: Groups of 4 characters separated by spaces (e.g., HR12 3456 7890 1234 5678 9) - Applied formatting to IBAN field display in AccountForm - Updated validation to check cleaned IBAN (without spaces) - Maintains backward compatibility with server-side validation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
31 lines
1003 B
TypeScript
31 lines
1003 B
TypeScript
export const formatCurrency = (amount:number) => {
|
|
// format number wirh 2 decimal places and a thousand separator
|
|
// amount is in cents
|
|
const formattedAmount = (amount/100).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
|
|
return(formattedAmount);
|
|
}
|
|
|
|
/**
|
|
* Formats an IBAN for display with proper spacing
|
|
* Format: XX12 XXXX XXXX XXXX XXXX XX
|
|
* First group: 2 letters (country) + 2 digits (check) = 4 chars
|
|
* Following groups: 4 characters each
|
|
* Last group: can be less than 4 characters
|
|
* @param iban - IBAN string without spaces
|
|
* @returns Formatted IBAN with spaces
|
|
*/
|
|
export const formatIban = (iban: string | null | undefined): string => {
|
|
if (!iban) return "";
|
|
|
|
// Remove any existing spaces
|
|
const cleaned = iban.replace(/\s/g, '');
|
|
|
|
// Split into groups: first 4 chars, then groups of 4
|
|
const groups: string[] = [];
|
|
for (let i = 0; i < cleaned.length; i += 4) {
|
|
groups.push(cleaned.slice(i, i + 4));
|
|
}
|
|
|
|
return groups.join(' ');
|
|
}
|