、、、、の5 つの要素firstName
を持つフォームがあります。lastName
username
password
passwordConfirmation
var errors = [];
var errorsText = [];
function generateError(messageText, elementIdentifier) {
var messageText = messageText;
var elementIdentifier = elementIdentifier;
errors.push(elementIdentifier);
errorsText.push(messageText);
return false;
}
function validateRegistrationForm(firstName, lastName, username, password, passwordConfirmation) {
formReset();
//alert("validateRegistrationForm() has been called");
var firstName = firstName;
//alert("First Name = \'" + firstName + "\'");
var lastName = lastName;
//alert("Last Name = \'" + lastName + "\'");
var username = username;
//alert("Username = \'" + username + "\'");
var password = password;
//alert("Password = \'" + password + "\'");
var passwordConfirmation = passwordConfirmation;
//alert("Password Confirmation = \'" + passwordConfirmation + "\'");
if ( ( firstName == null ) || ( firstName == "" ) ) {
//alert("//firstname hasn't been filled out");
generateError("You must provide a First Name", "firstName");
}
if ( ( lastName == null ) || ( lastName == "" ) ) {
//lastname hasn't been filled out
generateError("You must provide a Last Name", "lastName");
}
if ( ( username == null ) || ( username == "" ) ) {
//username hasn't been filled out
generateError("You must enter a Username", "username");
}
if ( ( password == null ) || ( password == "" ) ) {
//password hasn't been filled out
generateError("You haven\'t entered a password", "password");
}
if ( ( passwordConfirmation == null ) || ( passwordConfirmation == "" ) ) {
//passwordconfirmation hasn't been filled out
generateError("You haven\'t confirmed your password", "passwordConfirmation");
}
validatePassword(password, passwordConfirmation);
}
すべてを処理するより良い方法はありif statements
ますか?