Skip to content

Commit d1a575e

Browse files
committed
Add email regex validation and remove leading/trailing space for email/username on sign up
1 parent 3d89164 commit d1a575e

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

ai/usage-log.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,4 +335,30 @@ Fix Docker networking bug where middleware (server-side) and browser (client-sid
335335

336336
---
337337

338+
## Entry 11
339+
340+
# Date/Time:
341+
2025-09-16 20:00
342+
343+
# Tool:
344+
ChatGPT (model: GPT-4.1)
345+
346+
# Prompt/Command:
347+
Request to generate email regex validation.
348+
349+
# Output Summary:
350+
- Comprehensive regex pattern for validating email addresses
351+
- Support for various email formats including subdomains and special characters
352+
- Edge case handling for common email validation pitfalls
353+
354+
# Action Taken:
355+
- [x] Accepted as-is
356+
- [ ] Modified
357+
- [ ] Rejected
358+
359+
# Author Notes:
360+
- I validated correctness, security, and performance of the code
361+
362+
---
363+
338364

frontend/src/app/components/auth/SignUpComponent.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
* debounced password validation, password complexity requirements with visual indicators,
66
* and enhanced UX patterns.
77
* 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.
812
*/
913

1014
"use client";
@@ -101,21 +105,33 @@ export default function SignupForm() {
101105
//#region other methods
102106
const onRegister = async (e: React.MouseEvent) => {
103107
e.preventDefault();
108+
109+
const trimmedUsername = username.trim();
110+
const trimmedEmail = email.trim();
104111
// Specific validation checks with toast messages
105-
if (!username) {
112+
if (!trimmedUsername) {
106113
toast.error("Username is required!", {
107114
description: "Please enter a username to continue.",
108115
});
109116
return;
110117
}
111118

112-
if (!email) {
119+
if (!trimmedEmail) {
113120
toast.error("Email is required!", {
114121
description: "Please enter your email address.",
115122
});
116123
return;
117124
}
118125

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+
119135
if (!password) {
120136
toast.error("Password is required!", {
121137
description: "Please create a password for your account.",
@@ -146,7 +162,7 @@ export default function SignupForm() {
146162

147163
try {
148164
// sign up using apis - Axios automatically parses JSON
149-
const response = await signup(username, email, password);
165+
const response = await signup(trimmedUsername, trimmedEmail, password);
150166

151167
// Use reusable success handler
152168
handleApiSuccess(
@@ -155,7 +171,7 @@ export default function SignupForm() {
155171
response.data.data,
156172
);
157173

158-
//Redirect to login after short delay (commented out for testing)
174+
//Redirect to login after short delay
159175
setTimeout(() => {
160176
router.push("/auth/login");
161177
}, 1500);

0 commit comments

Comments
 (0)