5
5
* debounced password validation, password complexity requirements with visual indicators,
6
6
* and enhanced UX patterns.
7
7
* Author Review: I validated correctness, security, and performance of the code.
8
+ *
9
+ * Tool: ChatGPT (model: GPT-4.1, date: 2025-09-16)
10
+ * Purpose: To Generate email regex validation
11
+ * Author Review: I validated correctness, security, and performance of the code.
8
12
*/
9
13
10
14
"use client" ;
@@ -101,21 +105,33 @@ export default function SignupForm() {
101
105
//#region other methods
102
106
const onRegister = async ( e : React . MouseEvent ) => {
103
107
e . preventDefault ( ) ;
108
+
109
+ const trimmedUsername = username . trim ( ) ;
110
+ const trimmedEmail = email . trim ( ) ;
104
111
// Specific validation checks with toast messages
105
- if ( ! username ) {
112
+ if ( ! trimmedUsername ) {
106
113
toast . error ( "Username is required!" , {
107
114
description : "Please enter a username to continue." ,
108
115
} ) ;
109
116
return ;
110
117
}
111
118
112
- if ( ! email ) {
119
+ if ( ! trimmedEmail ) {
113
120
toast . error ( "Email is required!" , {
114
121
description : "Please enter your email address." ,
115
122
} ) ;
116
123
return ;
117
124
}
118
125
126
+ // check if email format is valid using simple regex
127
+ const emailPattern = / ^ [ ^ \s @ ] + @ [ ^ \s @ ] + \. [ ^ \s @ ] + $ / ;
128
+ if ( ! emailPattern . test ( trimmedEmail ) ) {
129
+ toast . error ( "Invalid email format!" , {
130
+ description : "Please enter a valid email address." ,
131
+ } ) ;
132
+ return ;
133
+ }
134
+
119
135
if ( ! password ) {
120
136
toast . error ( "Password is required!" , {
121
137
description : "Please create a password for your account." ,
@@ -146,7 +162,7 @@ export default function SignupForm() {
146
162
147
163
try {
148
164
// sign up using apis - Axios automatically parses JSON
149
- const response = await signup ( username , email , password ) ;
165
+ const response = await signup ( trimmedUsername , trimmedEmail , password ) ;
150
166
151
167
// Use reusable success handler
152
168
handleApiSuccess (
@@ -155,7 +171,7 @@ export default function SignupForm() {
155
171
response . data . data ,
156
172
) ;
157
173
158
- //Redirect to login after short delay (commented out for testing)
174
+ //Redirect to login after short delay
159
175
setTimeout ( ( ) => {
160
176
router . push ( "/auth/login" ) ;
161
177
} , 1500 ) ;
0 commit comments