Daniel 🛸• 44,230
@danielmrz-dev
Posted
Olá @mypetonthenet!
Seu projeto ficou excelente!
Uma sugestão é simplificar a lógica de validação utilizando operadores ternários. Isso pode reduzir a quantidade de código e tornar o mesmo mais conciso. Aqui está um exemplo para a função validateDay():
function validateDay() {
erroDia.innerHTML = diaNascimento.value.length === 0 ? 'This field is required' : (diaNascimento.value > 31 ? 'Must be a valid day' : '');
erroDia.style.opacity = diaNascimento.value.length === 0 || diaNascimento.value > 31 ? '1' : '0';
textDay.style.color = diaNascimento.value.length === 0 || diaNascimento.value > 31 ? '#F25D07' : '#716f6f';
diaNascimento.style.border = diaNascimento.value.length === 0 || diaNascimento.value > 31 ? '1px solid #F25D07' : '1px solid #dbdbdb';
}
Essa abordagem utiliza operadores ternários para simplificar as condições e as atribuições de valores, resultando em um código mais curto e fácil de entender. Você pode aplicar uma lógica semelhante para as outras funções de validação.
Espero que ajude!
Marked as helpful
0