forked from atums.world/backend
re-order alot, move to bun redis, generalized
This commit is contained in:
parent
a646607597
commit
8a9499be85
51 changed files with 559 additions and 916 deletions
37
src/lib/validators/invite.ts
Normal file
37
src/lib/validators/invite.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
const inviteRestrictions: { min: number; max: number; regex: RegExp } = {
|
||||
min: 4,
|
||||
max: 15,
|
||||
regex: /^[a-zA-Z0-9]+$/,
|
||||
};
|
||||
|
||||
export function isValidInvite(invite: string): {
|
||||
valid: boolean;
|
||||
error?: string;
|
||||
} {
|
||||
if (!invite) {
|
||||
return { valid: false, error: "" };
|
||||
}
|
||||
|
||||
if (invite.length < inviteRestrictions.min) {
|
||||
return {
|
||||
valid: false,
|
||||
error: `Invite code must be at least ${inviteRestrictions.min} characters long`,
|
||||
};
|
||||
}
|
||||
|
||||
if (invite.length > inviteRestrictions.max) {
|
||||
return {
|
||||
valid: false,
|
||||
error: `Invite code can't be longer than ${inviteRestrictions.max} characters`,
|
||||
};
|
||||
}
|
||||
|
||||
if (!inviteRestrictions.regex.test(invite)) {
|
||||
return {
|
||||
valid: false,
|
||||
error: "Invite code contains invalid characters",
|
||||
};
|
||||
}
|
||||
|
||||
return { valid: true };
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue