|
| 1 | +const input = document.querySelector("input"), |
| 2 | + showHide = document.querySelector(".show_hide"), |
| 3 | + color_box = document.querySelector(".color_box"), |
| 4 | + iconText = document.querySelector(".icon-text"), |
| 5 | + text = document.querySelector(".text"); |
| 6 | + |
| 7 | +showHide.addEventListener("click", ()=>{ |
| 8 | + if(input.type === "password"){ |
| 9 | + input.type = "text"; |
| 10 | + showHide.classList.replace("fa-eye-slash","fa-eye"); |
| 11 | + }else { |
| 12 | + input.type = "password"; |
| 13 | + showHide.classList.replace("fa-eye","fa-eye-slash"); |
| 14 | + } |
| 15 | +}); |
| 16 | + |
| 17 | +let alphabet = /[a-zA-Z]/, |
| 18 | + numbers = /[0-9]/, |
| 19 | + scharacters = /[!,@,#,$,%,^,&,*,?,_,(,),-,+,=,~]/; |
| 20 | + |
| 21 | +input.addEventListener("keyup", ()=>{ |
| 22 | + color_box.classList.add("active"); |
| 23 | + |
| 24 | + let val = input.value; |
| 25 | + if(val.match(alphabet) || val.match(numbers) || val.match(scharacters)){ |
| 26 | + text.textContent = "Password is weak"; |
| 27 | + input.style.borderColor = "#FF6333"; |
| 28 | + showHide.style.color = "#FF6333"; |
| 29 | + iconText.style.color = "#FF6333"; |
| 30 | + } |
| 31 | + if(val.match(alphabet) && val.match(numbers) && val.length >= 6){ |
| 32 | + text.textContent = "Password is medium"; |
| 33 | + input.style.borderColor = "#cc8500"; |
| 34 | + showHide.style.color = "#cc8500"; |
| 35 | + iconText.style.color = "#cc8500"; |
| 36 | + } |
| 37 | + if(val.match(alphabet) && val.match(numbers) && val.match(scharacters) && val.length >= 8){ |
| 38 | + text.textContent = "Password is strong"; |
| 39 | + input.style.borderColor = "#22C32A"; |
| 40 | + showHide.style.color = "#22C32A"; |
| 41 | + iconText.style.color = "#22C32A"; |
| 42 | + } |
| 43 | + if(val == ""){ |
| 44 | + color_box.classList.remove("active"); |
| 45 | + input.style.borderColor = "#A6A6A6"; |
| 46 | + showHide.style.color = "#A6A6A6"; |
| 47 | + iconText.style.color = "#A6A6A6"; |
| 48 | + } |
| 49 | +}); |
0 commit comments