make username and coin name alphanumerical only

This commit is contained in:
Face 2025-05-31 12:58:24 +03:00
parent 8d12c679ae
commit c2208335a5
2 changed files with 16 additions and 0 deletions

View file

@ -16,6 +16,15 @@ async function validateInputs(name: string, symbol: string, iconFile: File | nul
throw error(400, 'Symbol must be between 2 and 10 characters'); throw error(400, 'Symbol must be between 2 and 10 characters');
} }
const alphanumericRegex = /^[a-zA-Z0-9]+$/;
if (!alphanumericRegex.test(name)) {
throw error(400, 'Coin name must contain only letters and numbers');
}
if (!alphanumericRegex.test(symbol)) {
throw error(400, 'Coin symbol must contain only letters and numbers');
}
const nameAppropriate = await isNameAppropriate(name); const nameAppropriate = await isNameAppropriate(name);
if (!nameAppropriate) { if (!nameAppropriate) {
throw error(400, 'Coin name contains inappropriate content'); throw error(400, 'Coin name contains inappropriate content');

View file

@ -24,6 +24,13 @@ async function validateInputs(name: string, bio: string, username: string, avata
throw error(400, 'Username must be between 3 and 30 characters'); throw error(400, 'Username must be between 3 and 30 characters');
} }
if (username) {
const alphanumericRegex = /^[a-zA-Z0-9]+$/;
if (!alphanumericRegex.test(username)) {
throw error(400, 'Username must contain only letters and numbers');
}
}
if (username && !(await isNameAppropriate(username))) { if (username && !(await isNameAppropriate(username))) {
throw error(400, 'Username contains inappropriate content'); throw error(400, 'Username contains inappropriate content');
} }