TelegramPWA/src/util/username.ts
2023-12-04 14:56:18 +01:00

12 lines
352 B
TypeScript

export const MIN_USERNAME_LENGTH = 5;
export const MAX_USERNAME_LENGTH = 32;
export const USERNAME_REGEX = /^\D([a-zA-Z0-9_]+)$/;
export function isUsernameValid(username: string) {
return username.length === 0 || (
username.length >= MIN_USERNAME_LENGTH
&& username.length <= MAX_USERNAME_LENGTH
&& USERNAME_REGEX.test(username)
);
}