Username bug
Closed this issue · 0 comments
akbarjorayev commented
The code:
export function isValidUsername(username) {
if (username.length < 2) {
return { msg: 'Write more than 1 characters', ok: false }
}
const hasWhitespace = /\s/.test(username.trim())
if (hasWhitespace) {
return { msg: 'Contains whitespace', ok: false }
}
const regex = /^[A-Za-z0-9_]+$/
if (!regex.test(username.trim())) {
return { msg: 'Invalid characters', ok: false }
}
return { msg: 'Valid username', ok: true }
}