@@ -50,26 +50,63 @@ <h1>Welcome to <span class="brand">SkillWise</span></h1>
50
50
</div>
51
51
<p class="suggestion">
52
52
<small>Use special characters and numbers for a strong password</small>
53
+
53
54
</p> -->
54
- < button type ="submit " class ="signin-btn "> Sign In</ button >
55
+
56
+ < button type ="submit " class ="signin-btn " id ="submit "> Sign In</ button >
57
+
55
58
< p class ="signup-link "> Don't have an account? < a href ="./signup.html "> Sign up here</ a > </ p >
56
59
</ form >
57
60
</ div >
58
61
</ div >
59
62
< script src ="https://kit.fontawesome.com/a076d05399.js "> </ script >
60
- < script >
61
- const togglePassword = document . querySelector ( "#togglePassword" ) ;
62
- const passwordInput = document . querySelector ( "#password" ) ;
63
-
64
- togglePassword . addEventListener ( "click" , function ( ) {
65
- const type = passwordInput . getAttribute ( "type" ) === "password" ? "text" : "password" ;
66
- passwordInput . setAttribute ( "type" , type ) ;
67
63
68
- this . classList . toggle ( "fa-eye-slash" ) ;
69
- this . classList . toggle ( "fa-eye" ) ;
70
- } ) ;
64
+ < script >
65
+ const togglePassword = document . querySelector ( "#togglePassword" ) ;
66
+ const passwordInput = document . querySelector ( "#password" ) ;
67
+ const submitBtn = document . querySelector ( "#submit" ) ;
68
+ const emailInput = document . querySelector ( "#email" ) ;
69
+
70
+ togglePassword . addEventListener ( "click" , function ( ) {
71
+ const type = passwordInput . getAttribute ( "type" ) === "password" ? "text" : "password" ;
72
+ passwordInput . setAttribute ( "type" , type ) ;
73
+
74
+ this . classList . toggle ( "fa-eye-slash" ) ;
75
+ this . classList . toggle ( "fa-eye" ) ;
76
+ } ) ;
77
+
78
+
79
+
80
+ submitBtn . addEventListener ( "click" , ( e ) => {
81
+ e . preventDefault ( ) ;
82
+
83
+ const email = emailInput . value ;
84
+ const emailError = document . getElementById ( "emailError" ) ;
85
+
86
+
87
+ const emailPattern = / ^ [ a - z A - Z 0 - 9 . _ - ] + @ [ a - z A - Z 0 - 9 . - ] + \. [ a - z A - Z ] { 2 , 6 } $ / ;
88
+
89
+ if ( ! emailPattern . test ( email ) ) {
90
+
91
+ if ( ! emailError ) {
92
+ const errorMsg = document . createElement ( "p" ) ;
93
+ errorMsg . id = "emailError" ;
94
+ errorMsg . style . color = "red" ;
95
+ errorMsg . textContent = "Email is incorrect. Please enter a valid email address." ;
96
+ emailInput . parentElement . appendChild ( errorMsg ) ;
97
+ }
98
+ } else {
99
+
100
+ if ( emailError ) {
101
+ emailError . remove ( ) ;
102
+ }
103
+
104
+ e . target . closest ( "form" ) . submit ( ) ;
105
+ }
106
+ } ) ;
71
107
72
108
</ script >
109
+
73
110
74
111
</ body >
75
112
</ html >
0 commit comments