mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1// Regex for base32 string for testing reset code 2const RESET_CODE_REGEX = /^[A-Z2-7]{5}-[A-Z2-7]{5}$/ 3 4export function checkAndFormatResetCode(code: string): string | false { 5 // Trim the reset code 6 let fixed = code.trim().toUpperCase() 7 8 // Add a dash if needed 9 if (fixed.length === 10) { 10 fixed = `${fixed.slice(0, 5)}-${fixed.slice(5, 10)}` 11 } 12 13 // Check that it is a valid format 14 if (!RESET_CODE_REGEX.test(fixed)) { 15 return false 16 } 17 18 return fixed 19}