frontend: fix validation

This commit is contained in:
Alex
2025-02-26 21:39:42 +01:00
parent c607622185
commit dde3b3d47b

View File

@@ -65,46 +65,40 @@
*/ */
function validateField(name, value, required) { function validateField(name, value, required) {
if (value === null || (typeof value === 'string' && !value.trim() && !required)) return null; if (value === null || (typeof value === 'string' && !value.trim() && !required)) return null;
switch (name) { if (name.includes('membership_start_date')) {
case 'membership_start_date': return typeof value === 'string' && value.trim() ? null : $t('validation.date');
return typeof value === 'string' && value.trim() ? null : $t('validation.date'); } else if (name.includes('email')) {
case 'email': return typeof value === 'string' && /^\S+@\S+\.\S+$/.test(value)
return typeof value === 'string' && /^\S+@\S+\.\S+$/.test(value) ? null
? null : $t('validation.email');
: $t('validation.email'); } else if (name.includes('password')) {
case 'password': if (typeof value === 'string' && value.length < 8) {
case 'password2': return $t('validation.password');
if (typeof value === 'string' && value.length < 8) { }
return $t('validation.password'); if (otherPasswordValue && value !== otherPasswordValue) {
} return $t('validation.password_match');
if (otherPasswordValue && value !== otherPasswordValue) { }
return $t('validation.password_match'); return null;
} } else if (name.includes('phone')) {
return null; return typeof value === 'string' && /^\+?[0-9\s()-]{7,}$/.test(value)
case 'phone': ? null
return typeof value === 'string' && /^\+?[0-9\s()-]{7,}$/.test(value) : $t('validation.phone');
? null } else if (name.includes('zip_code')) {
: $t('validation.phone'); return typeof value === 'string' && /^\d{5}$/.test(value) ? null : $t('validation.zip_code');
case 'zip_code': } else if (name.includes('iban')) {
return typeof value === 'string' && /^\d{5}$/.test(value) return typeof value === 'string' && /^[A-Z]{2}\d{2}[A-Z0-9]{1,30}$/.test(value)
? null ? null
: $t('validation.zip_code'); : $t('validation.iban');
case 'iban': } else if (name.includes('bic')) {
return typeof value === 'string' && /^[A-Z]{2}\d{2}[A-Z0-9]{1,30}$/.test(value) return typeof value === 'string' && /^[A-Z]{6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3})?$/.test(value)
? null ? null
: $t('validation.iban'); : $t('validation.bic');
case 'bic': } else if (name.includes('licence_number')) {
return typeof value === 'string' && return typeof value === 'string' && value.length == 11 ? null : $t('validation.licence');
/^[A-Z]{6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3})?$/.test(value) } else {
? null return typeof value === 'string' && !value.trim() && required
: $t('validation.bic'); ? $t('validation.required')
case 'licence_number': : null;
return typeof value === 'string' && value.length == 11 ? null : $t('validation.licence');
default:
return typeof value === 'string' && !value.trim() && required
? $t('validation.required')
: null;
} }
} }