100-project-100-days-website/100_projects/57-password-validation-check-in/js/main.js
2023-04-19 17:30:52 +03:00
Ask

67 lines
1.6 KiB
JavaScript

{077f4ca28d29531e40cc506be135f568ce282f87 true 1588 main.js 0xc002aa24d0}

let pass = document.getElementById('pass');
let toggleBtn = document.getElementById('toggleBtn');
let lowerCase = document.getElementById('lower');
let upperCase = document.getElementById('upper');
let digit = document.getElementById('number');
let specialChar = document.getElementById('special');
let minlength = document.getElementById('length');
function checkPassword(data){
const lower = new RegExp('(?=.*[a-z])');
const upper = new RegExp('(?=.*[A-Z])');
const number = new RegExp('(?=.*[0-9])');
const special = new RegExp('(?=.*[!@#\$%\^&\*])');
const length = new RegExp('(?=.{8,})');
// lower
if(lower.test(data)){
lowerCase.classList.add('valid');
} else {
lowerCase.classList.remove('valid');
}
// upper
if(upper.test(data)){
upperCase.classList.add('valid');
} else {
upperCase.classList.remove('valid');
}
// number
if(number.test(data)){
digit.classList.add('valid');
} else {
digit.classList.remove('valid');
}
// special
if(special.test(data)){
specialChar.classList.add('valid');
} else {
specialChar.classList.remove('valid');
}
// length
if(length.test(data)){
minlength.classList.add('valid');
} else {
minlength.classList.remove('valid');
}
}
// Show\Hide
toggleBtn.onclick = function(){
if(pass.type === 'password'){
pass.setAttribute('type', 'text');
toggleBtn.classList.add('hide');
} else {
pass.setAttribute('type', 'password');
toggleBtn.classList.remove('hide');
}
}