2022-02-23 13:52:06 +00:00
|
|
|
/** Check whether a hex color is valid. */
|
2020-10-10 23:32:27 +00:00
|
|
|
export function isValidHexColor(color: string): boolean {
|
|
|
|
return (
|
|
|
|
/^#(?:[a-f\d]{8}|[a-f\d]{6}|[a-f\d]{4}|[a-f\d]{3})$/i.exec(color) !== null
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-02-23 13:52:06 +00:00
|
|
|
/** Check whether a username is a valid Tildes username. */
|
2020-10-10 23:32:27 +00:00
|
|
|
export function isValidTildesUsername(username: string): boolean {
|
|
|
|
// Validation copied from Tildes source code:
|
|
|
|
// https://gitlab.com/tildes/tildes/blob/master/tildes/tildes/schemas/user.py
|
|
|
|
return (
|
|
|
|
username.length >= 3 &&
|
|
|
|
username.length <= 20 &&
|
|
|
|
/^[a-z\d]([a-z\d]|[_-](?![_-]))*[a-z\d]$/i.exec(username) !== null
|
|
|
|
);
|
|
|
|
}
|