Skip to content

Commit

Permalink
Merge pull request #36 from maxonary/refactor/utils-isValidUsername/b…
Browse files Browse the repository at this point in the history
…ackend

Refactor utils-isValidUsername in backend - Fixes #35
  • Loading branch information
maxonary authored Mar 19, 2024
2 parents 156dd23 + a01bc29 commit 41e1424
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions backend/src/utils/isValidUsername.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export const isValidUsername = (username: string, gameType: string) => {
const regex = gameType === 'Java Edition' ? /^[a-zA-Z0-9_]{3,16}$/ : /^[a-zA-Z0-9_][a-zA-Z0-9_ ]{1,14}[a-zA-Z0-9_]$/;
return regex.test(username);
const JAVA_EDITION_USERNAME_PATTERN = /^\w{3,16}$/;
const OTHER_EDITION_USERNAME_PATTERN = /^\w[\w ]{1,14}\w$/;

export const isValidUsername = (username: string, gameType: string): boolean => {
const usernamePattern = gameType === 'Java Edition' ? JAVA_EDITION_USERNAME_PATTERN : OTHER_EDITION_USERNAME_PATTERN;
return usernamePattern.test(username);
}

0 comments on commit 41e1424

Please sign in to comment.