Vertragsverwaltung_Plusfit24/utils/sepaValidator.js
2026-02-10 15:29:29 +00:00

26 lines
679 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const iban = require('iban');
/**
* Stufe 1 Formale SEPA-Prüfung
* @returns {string|null} Fehlermeldung oder null
*/
module.exports = function validateSepa({ ibanValue, bic, mandatsreferenz }) {
// IBAN prüfen (Länge + Prüfziffer)
if (!ibanValue || !iban.isValid(ibanValue)) {
return 'Ungültige IBAN';
}
// BIC prüfen (8 oder 11 alphanumerische Zeichen)
if (!bic || !/^[A-Z0-9]{8}([A-Z0-9]{3})?$/.test(bic)) {
return 'Ungültiger BIC';
}
// Mandatsreferenz prüfen
if (!mandatsreferenz || mandatsreferenz.trim().length < 4) {
return 'Ungültige Mandatsreferenz';
}
return null; // ✅ alles ok
};