mirror of
https://github.com/mudabbir-ahmad/web-project.git
synced 2026-10-07 20:20:20 +00:00
new file: .config/configstore/update-notifier-npm.json new file: .config/configstore/update-notifier-npm.json.2701252402 new file: .replit new file: .vscode/launch.json new file: Internet.html new file: about.html new file: case.html new file: cooling.html new file: cpu.html new file: css/about.css new file: css/home.css new file: css/log copy.css new file: css/log.css new file: css/parts.css new file: css/pc.css new file: css/profile.css new file: global.css new file: global.js new file: gpu.html new file: hdd.html new file: home.html new file: images/pc-case.png new file: images/sal.jpeg new file: includes/dbh.inc.php new file: includes/functions.inc.php new file: includes/login.inc.php new file: includes/signup.inc.php new file: index.html new file: js/log copy.js new file: js/log.js new file: keyb.html new file: log copy.html new file: log.html new file: monitor.html new file: mouse.html new file: pc.html new file: profile.html new file: psu.html new file: ram.html new file: register.html new file: replit.nix new file: ssd.html
55 lines
2.2 KiB
JavaScript
55 lines
2.2 KiB
JavaScript
const form = document.querySelector("form")
|
|
eField = form.querySelector(".email"),
|
|
eInput = eField.querySelector("input"),
|
|
pField = form.querySelector(".password"),
|
|
pInput = pField.querySelector("input");
|
|
|
|
|
|
form.onsubmit = (e)=>{
|
|
e.preventDefault(); //preventing from form submitting
|
|
//if email and password is blank then add shake class in it else call specified function
|
|
(eInput.value == "") ? eField.classList.add("shake", "error") : checkEmail();
|
|
(pInput.value == "") ? pField.classList.add("shake", "error") : checkPass();
|
|
|
|
|
|
setTimeout(()=>{ //remove shake class after 500ms
|
|
eField.classList.remove("shake");
|
|
pField.classList.remove("shake");
|
|
}, 500);
|
|
|
|
|
|
eInput.onkeyup = ()=>{checkEmail();} //calling checkEmail function on email input keyup
|
|
pInput.onkeyup = ()=>{checkPass();} //calling checkPassword function on pass input keyup
|
|
|
|
|
|
function checkEmail(){ //checkEmail function
|
|
let pattern = /^[^ ]+@[^ ]+\.[a-z]{2,3}$/; //pattern for validate email
|
|
if(!eInput.value.match(pattern)){ //if pattern not matched then add error and remove valid class
|
|
eField.classList.add("error");
|
|
eField.classList.remove("valid");
|
|
let errorTxt = eField.querySelector(".error-txt");
|
|
//if email value is not empty then show please enter valid email else show Email can't be blank
|
|
(eInput.value != "") ? errorTxt.innerText = "Enter a valid email address" : errorTxt.innerText = "Email can't be blank";
|
|
}else{ //if pattern matched then remove error and add valid class
|
|
eField.classList.remove("error");
|
|
eField.classList.add("valid");
|
|
}
|
|
}
|
|
|
|
|
|
function checkPass(){ //checkPass function
|
|
if(pInput.value == ""){ //if pass is empty then add error and remove valid class
|
|
pField.classList.add("error");
|
|
pField.classList.remove("valid");
|
|
}else{ //if pass is empty then remove error and add valid class
|
|
pField.classList.remove("error");
|
|
pField.classList.add("valid");
|
|
}
|
|
}
|
|
|
|
|
|
//if eField and pField doesn't contains error class that mean user filled details properly
|
|
if(!eField.classList.contains("error") && !pField.classList.contains("error")){
|
|
window.location.href = form.getAttribute("action"); //redirecting user to the specified url which is inside action attribute of form tag
|
|
}
|
|
}; |