Validating email

Hello guys, how do i edit this code into this code? I am getting hide/show element js style call error.
this is the code i want to put it in.

// validating email 
function ValidateEmail(userEmail) 
{
 if (/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(myForm.emailAddr.value))
  {
    return (userEmail)
  }else{
    window.alert("You have entered an invalid email address!")
    return (ValidateEmail)
    }
}

This is the main code I am working with

Moralis.initialize("9PmarGeRjGYUJzL0fkLgY7TK4h9r6BryHGBo7wC0");
Moralis.serverURL = 'https://imgvpmtqkpng.moralis.io:2053/server'

init = async () => {
    hideElement(usrInfoDiv);
    hideElement(hwtoMM);
    window.web3 = await Moralis.Web3.enable();
    // await window.ethereum.send('eth_requestAccounts');
    // window.web3 = new Web3(window.web3.currentProvider);
    // window.ethereum.enable();
    initUser();
}

initUser = async () => {
    if (await Moralis.User.current()){
        hideElement(usrConnectButton);
        showElement(usrPrflButton);
    }else{
        showElement(usrConnectButton);
        hideElement(usrPrflButton);
    }
}

login = async() => {
    let delay = ms => new Promise (res => setTimeout(res, ms));
    try {
        await Moralis.Web3.authenticate();
        initUser(); 
    } catch (error) {
        showElement(hwtogdMM)
        window.alert("Та METAMASK эсвэл түрүүвчээ холбоно уу? ");
        await delay(10000)
        await hideElement(hwtogdMM)
    }
}

logout = async () => {
    await Moralis.User.logOut(); 
    hideElement(usrInfoDiv);
    initUser();
}


openUsrInfo = async ()=> {
    user = await Moralis.User.current();
    if(user) {
        const email = user.get('email');
        if(email) {
            userEmail.value = email; //made change to validate email to userEmail from userEmail to function
        }else{
            userEmail.vlaue= "";
        }
        userEmail.value = user.get('username'); 
    const usrAvatarImg = user.get('avatar'); 
        if(usrAvatarImg){
            usrAvatarImg.src = usrFileAvatar.url(); 
            showElement(usrAvatarImg);
        }else{
            hideElement(usrAvatarImg);
        }
    showElement(usrInfoDiv);
    } else {
        login();
    }
}
saveUserInfo = async() => {
    user.set('email', userEmail.value); //same changes have applied to the validate email function from user to functin 
    user.set('username', textUsrName.value);
    if (usrFileAvatar.files.length > 0) {
        const file = usrFileAvatar.files[0];
        const name = "avatarprfl.jpg";
        const avatar = new Moralis.File(name, file);
        user.set('avatar', avatar);
      }
      await user.save();
      alert("Таны мэдээлэл амжилттай хадгалагдлаа");
      openUsrInfo();
}


hideElement = (element) => element.style.display = "none"; 
showElement = (element) => element.style.display = "block";

const usrConnectButton = document.getElementById("usrCnnctButton");
const usrPrflButton = document.getElementById("usrprflButton"); 
usrPrflButton.onclick= openUsrInfo;


const textUsrName = document.getElementById("textUsrnm"); 
const userEmail = document.getElementById("usremail"); 
const usrAvatarImg = document.getElementById("imgAvatar"); 
const usrFileAvatar = document.getElementById("fileAvatar"); 


const hwtoMM = document.getElementById("hwtogdMM"); 

usrConnectButton.onclick= login

const usrInfoDiv = document.getElementById("usrInfo"); 

document.getElementById("ClsUsrInfobttn").onclick = () => hideElement(usrInfoDiv)
document.getElementById("logOutbttn").onclick = logout;
document.getElementById("SaveUsrInfobttn").onclick = saveUserInfo;




init();

Alright never mind I fixed it.

1 Like

Hi, @bouncyknighter,

Can you post the solution here so that it helps others as well.

Thank you. :smiley: