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