So this is my code: pressing a button creates html mssg: Inside the class Student, I tried to check names for inv characters and empty fields. Then I wanted to pass through another f-on which would check if both f-ons doing their thing and to call her outside the class. I tried different ways to solve it but returns the same result. Please if someone knows to resolve or explain in more details would be grateful.
TY all.
constructor(fullName, address, phone, course) {
this._fullName = fullName;
this.address = address;
this.phone = phone;
this.course = course;
}
validateName(text) {
let regex = /^[A-Za-z0-9 ]+$/;
let isValid = regex.test(text);
if (!isValid) {
alert("Contains Special characters");
} else {
alert("OK");
}
}
checkName(text) {
text = text.trim();
if (text === "") {
throw new Error("The name can not be empty");
} else {
return (this._fullName = text);
}
}
sucess(text) {
let notChars = this.validateName(text);
let notEmpty = this.checkName(text);
if (!notChars || !notEmpty) {
return alert("chars or empty");
} else {
return alert("ok");
}
}
getInfo() {
return `Name: ${this._fullName} <br> Address: ${this.address}<br> Phone: ${this.phone}<br> Course: ${this.course}`;
}
}
let fullName = $("#fullName");
let address1 = $("#inputAddress");
let address2 = $("#inputAddress2");
let inputCity = $("#inputCity");
let inputZip = $("#inputZip");
let phone = $("#phoneNumber");
let show = $("#show");
let course = $("#course");
$("#signInBtn").on("click", (e) => {
e.preventDefault();
let address = `${address1.val()} ${address2.val()} ${inputCity.val()} ${inputZip.val()}`;
let student1 = new Student(
fullName.val(),
address,
phone.val(),
course.val()
);
show.html(student1.sucess("Steva"));
});