On my website, I have implemented a login system using LocalStorage and would like to incorporate an error message feature for incorrect entries. Since I already have assistance for handling email errors on another page, I am interested in applying that same error message format to other types of errors as well. Is there a way to reuse the Email Error message for other elements, or do I need to create individual styles and messages for each error? If it is possible, I would like to integrate the Email Error message into the "checkRegisterEnter" and "checkRegisterPassword" functions for alert replacements. The existing email validation code can be found below.
Javascript code:
function checkRegisterEnter(){
if(givenname.value == 0){
alert("Name field is Empty!")
}
}
function checkRegisterPassword(){
if(password.value !== password2.value) {
alert('The first password does not match the second!')
}
}
//Email_Check
const checkrform = document.getElementById("register.form")[0];
const checkremail = document.getElementById("ri3");
let remailerror = checkremail;
while ((remailerror = remailerror.nextSilbing).nodeType != 1);
const remailRegExp = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
function addEvent(remailelement,remailevent,callback){
let previousEventCallBack = remailelement["on"+remailevent];
remailelement["on"+remailevent] = function (e) {const remailoutput = callback(e);
}
};
(Translated with Google Translate, errors may be included.)
Edit: Still seeking a solution to this problem. Any help would be greatly appreciated.