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