|
| 1 | +// const indicator = document.querySelector(".indicator"); |
| 2 | +const input = document.querySelector(".input"); |
| 3 | +const showBtn = document.querySelector(".showBtn") |
| 4 | +const weak = document.querySelector(".weak"); |
| 5 | +const medium = document.querySelector(".medium"); |
| 6 | +const strong = document.querySelector(".strong"); |
| 7 | +const text = document.querySelector(".text"); |
| 8 | + |
| 9 | +let regExpWeak = /[a-z]/; |
| 10 | +let regExpMedium = /\d+/; |
| 11 | +let regExpStrong = /.[!,@,#,$,%,^,&,*,(,)]/; |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | +document.getElementById("trigger").addEventListener("keyup", function() { |
| 16 | + |
| 17 | + if (input.value.length <= 3 && (input.value.match(regExpWeak) || input.value.match(regExpMedium) || input.value.match(regExpStrong))) no = 1; |
| 18 | + |
| 19 | + if (input.value.length >= 6 && ((input.value.match(regExpWeak) && input.value.match(regExpMedium)) || (input.value.match(regExpMedium) && input.value.match(regExpStrong)) || (input.value.match(regExpWeak) && input.value.match(regExpStrong)))) no = 2; |
| 20 | + |
| 21 | + if (input.value.length >= 6 && input.value.match(regExpWeak) && input.value.match(regExpMedium) && input.value.match(regExpStrong)) no = 3; |
| 22 | + |
| 23 | + if (no == 1) { |
| 24 | + weak.classList.add("active"); |
| 25 | + text.style.display = "block"; |
| 26 | + text.textContent = "Your password is too weak"; |
| 27 | + text.classList.add("weak"); |
| 28 | + } |
| 29 | + |
| 30 | + if (no == 2) { |
| 31 | + medium.classList.add("active"); |
| 32 | + text.textContent = "Your password is average"; |
| 33 | + text.classList.add("medium"); |
| 34 | + } else { |
| 35 | + medium.classList.remove("active"); |
| 36 | + text.classList.remove("medium"); |
| 37 | + } |
| 38 | + |
| 39 | + if (no == 3) { |
| 40 | + medium.classList.add("active"); |
| 41 | + strong.classList.add("active"); |
| 42 | + text.style.display = "block"; |
| 43 | + text.textContent = "Your password is strong"; |
| 44 | + text.classList.add("strong"); |
| 45 | + } else { |
| 46 | + strong.classList.remove("active"); |
| 47 | + text.classList.remove("strong"); |
| 48 | + } |
| 49 | + |
| 50 | + showBtn.style.display = "block"; |
| 51 | + showBtn.onclick = function() { |
| 52 | + if (input.type == "password") { |
| 53 | + input.type = "text"; |
| 54 | + showBtn.textContent = "HIDE"; |
| 55 | + showBtn.style.color = "#23ad5c"; |
| 56 | + } else { |
| 57 | + input.type = "password"; |
| 58 | + showBtn.textContent = "SHOW"; |
| 59 | + showBtn.style.color = "#000"; |
| 60 | + } |
| 61 | + } |
| 62 | + |
| 63 | +}); |
| 64 | + |
0 commit comments