1 回答
TA贡献1829条经验 获得超13个赞
你可以:
existingEmails
检索电子邮件后创建一个数组。然后在
checkEmailExists
函数中您将检查电子邮件是否在数组中。
<script>
var first_email = document.getElementById("email1")
, second_email = document.getElementById("email2")
, password = document.getElementById("password")
, confirm_password = document.getElementById("confirm_password");
//making an array of the email addresses from the XML file
var request = new XMLHttpRequest();
request.open("GET", "storedata.xml", false);
request.send();
var xml = request.responseXML;
var users = xml.getElementsByTagName("data");
const existingEmails = [];
for(var i = 0; i < users.length; i++) {
const emailTag = users[i].getElementsByTagName("email2");
const email = emailTag[0].childNodes[0].nodeValue;
existingEmails.push(email);
}
//checking if the email already exists
function checkEmailExists() {
if (existingEmails.includes(first_email.value)) {
first_email.setCustomValidity("This email address already exists! Please use another one.");
} else {
first_email.setCustomValidity('');
}
}
email1.onchange = checkEmailExists;
function validateMail() {
if(first_email.value != second_email.value) {
email2.setCustomValidity("Emails Don't Match");
} else {
email2.setCustomValidity('');
}
}
email2.onkeyup = validateMail;
- 1 回答
- 0 关注
- 83 浏览
添加回答
举报