mirror of
https://gitea.smigz.com/smiggiddy/odin-codeprojects.git
synced 2025-06-28 04:45:36 -04:00
feat: added javascript error validation
This commit is contained in:
parent
81be0a6509
commit
bcf0be5888
3 changed files with 40 additions and 8 deletions
|
@ -1,14 +1,31 @@
|
|||
const name = document.querySelector('#name'),
|
||||
email = document.querySelector('#email'),
|
||||
password = document.querySelector('#password'),
|
||||
passwordConfirmation = document.querySelector('#password-confirmation')
|
||||
passwordConfirmation = document.querySelector('#password-confirmation'),
|
||||
formInputs = document.querySelectorAll('.form-input')
|
||||
|
||||
password.addEventListener('keyup', e => {
|
||||
let error = '*Password must be at least 8 characters!';
|
||||
let errorDiv = password.nextElementSibling;
|
||||
|
||||
|
||||
passwordConfirmation.addEventListener('keyup', e => {
|
||||
if (password.value === e.target.value ) {
|
||||
console.log('they equal');
|
||||
if (password.value.length < 8) {
|
||||
password.style.borderColor = "#EF6262";
|
||||
errorDiv.textContent = error;
|
||||
} else {
|
||||
console.log('They don\'t equal');
|
||||
password.style.borderColor = "";
|
||||
errorDiv.textContent = "";
|
||||
}
|
||||
})
|
||||
|
||||
passwordConfirmation.addEventListener('keyup', e => {
|
||||
let error = '*Passwords do not match!';
|
||||
let errorDiv = passwordConfirmation.nextElementSibling;
|
||||
|
||||
if (password.value !== e.target.value ) {
|
||||
passwordConfirmation.style.borderColor = "#EF6262";
|
||||
errorDiv.textContent = error;
|
||||
} else {
|
||||
passwordConfirmation.style.borderColor = "";
|
||||
errorDiv.textContent = "";
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue