frontend: fix validation

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

View File

@@ -65,15 +65,13 @@
*/ */
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');
case 'email': } else if (name.includes('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');
case 'password': } else if (name.includes('password')) {
case 'password2':
if (typeof value === 'string' && value.length < 8) { if (typeof value === 'string' && value.length < 8) {
return $t('validation.password'); return $t('validation.password');
} }
@@ -81,27 +79,23 @@
return $t('validation.password_match'); return $t('validation.password_match');
} }
return null; return null;
case 'phone': } else if (name.includes('phone')) {
return typeof value === 'string' && /^\+?[0-9\s()-]{7,}$/.test(value) return typeof value === 'string' && /^\+?[0-9\s()-]{7,}$/.test(value)
? null ? null
: $t('validation.phone'); : $t('validation.phone');
case 'zip_code': } else if (name.includes('zip_code')) {
return typeof value === 'string' && /^\d{5}$/.test(value) return typeof value === 'string' && /^\d{5}$/.test(value) ? null : $t('validation.zip_code');
? null } else if (name.includes('iban')) {
: $t('validation.zip_code');
case 'iban':
return typeof value === 'string' && /^[A-Z]{2}\d{2}[A-Z0-9]{1,30}$/.test(value) return typeof value === 'string' && /^[A-Z]{2}\d{2}[A-Z0-9]{1,30}$/.test(value)
? null ? null
: $t('validation.iban'); : $t('validation.iban');
case 'bic': } else if (name.includes('bic')) {
return typeof value === 'string' && return typeof value === 'string' && /^[A-Z]{6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3})?$/.test(value)
/^[A-Z]{6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3})?$/.test(value)
? null ? null
: $t('validation.bic'); : $t('validation.bic');
case 'licence_number': } else if (name.includes('licence_number')) {
return typeof value === 'string' && value.length == 11 ? null : $t('validation.licence'); return typeof value === 'string' && value.length == 11 ? null : $t('validation.licence');
} else {
default:
return typeof value === 'string' && !value.trim() && required return typeof value === 'string' && !value.trim() && required
? $t('validation.required') ? $t('validation.required')
: null; : null;