尝试制作学校的通讯录,并输入两个字段并进行验证。似乎只验证第一个字段即名称,而忽略其余字段?我不确定是否有问题?它继续显示not a valid name
作为错误消息,而没有其他显示。
var validate_birthdate = my.isBirthdateBad(add_birthdate);
if (!valid_name.test(add_name)) {
alert("not a valid name");
valid_contact = false;
} else if (add_address.length > 0) {
if (!valid_address.test(add_address)) {
alert("not a valid address: " + add_address);
valid_contact = false;
}
} else if (add_birthdate.length > 0) {
if (!valid_birthdate.test(add_birthdate)) {
alert("not a valid birthdate");
valid_contact = false;
}
} else if (add_gender.length > 0) {
if (!valid_gender.test(add_gender)) {
alert("not a valid gender");
valid_contact = false;
}
} else if (add_ocupation.length > 0) {
if (!valid_occupation.test(add_occupation)) {
alert("not a valid job title");
valid_contact = false;
}
} else if (validate_birthdate) {
alert("not a valid birthdate: " + validate_birthdate);
valid_contact = false;
} else if (!(add_photo !== undefined) &&
(add_photo.length > 0) &&
(add_photo.indexOf("data:image/jpeg") === 0)) {
alert("image is not a jpeg!");
valid_contact = false;
}
// note the use of the "anonymous" function
// this returns an array of all of the matched contacts! Powerful!
var exists = _address_book_contacts.filter(function (contact) {
//check to see if the current "add_name"
// is found in the address book!
return contact.name() === add_name;
});
if (exists && (exists.length > 0)) {
if (!confirm("WARNING: " +
add_name +
" exists in database. " +
"Would you like to add again?")) {
valid_contact = false;
}
}