Как проверить несколько элементов в JavaScript, но не вкладывая ifs?
Не это ...
if ( username && username.length > 2 && username.length < 45 ) {
if ( password && password.length ... ) {
if ( birthday && birthday.isNumeric ...) {
if ( age && ... && ...) {
// Success
} else {
// Error 4
}
} else {
// Error 3
}
} else {
// Error 2
}
} else {
// Error 1
}
... точнее, это ...
validate({
validate 'username' and use these conditions 'username && username.length...',
validate 'password' and use these conditions 'password && password.length...',
validate 'birthday' and use these conditions 'birthday && birthday.isNumeric...',
validate 'age' and use these conditions 'age && ... && ...'
}, function(error) {
if ( !error ) {
// Success
}
});
У вас есть идеи? Спасибо за ответ!