JavaScriptで複数の項目を検証するにはどうすればよいですか?複数の商品をどのように検証しますか?
ないこの...
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
}
});
あなたは、任意のアイデアを持っていますか?返信ありがとう!
これらはネストされた 'if'ステートメントであり、オブジェクトではありません。 – SLaks
@SLaks Fixed ... –