Skip to content

Commit 26afae7

Browse files
committed
Add checks for username
letters, numbers, "." and "_" allowed, min length = 3, max length = 20 spaces not allowed (implicitly stated by usernameRegex)
1 parent 659d6e0 commit 26afae7

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Frontend/src/components/user/EditProfile.jsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ function EditProfile() {
4848
return;
4949
}
5050

51+
const usernameRegex = /^[a-zA-Z0-9._]{3,20}$/;
52+
const isValidUsername = usernameRegex.test(username)
53+
54+
if(!isValidUsername) {
55+
console.log("username is not valid:", username)
56+
setUsernameError(true)
57+
setErrorMessage("Username can only contain letters, numbers, dots (.), and underscores (_), and must be between 3 and 20 characters long.")
58+
return;
59+
}
60+
5161
if (password !== confirmPassword) {
5262
setPasswordError(true);
5363
setErrorMessage('Passwords do not match');

0 commit comments

Comments
 (0)