mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
feat: add username and email check in frontend
This commit is contained in:
1 parent
30aeacaf06
commit
c5ccf03ac5
15 files changed
+95
-64
No files matched your search
@@ -47,42 +47,3 @@ export function verifyJWT(token) {
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export function isValidUsername(username) {
|
||||
// Define a regular expression pattern for a valid Linux username.
|
||||
const usernamePattern = /^[a-z][a-z0-9_-]*$/
|
||||
|
||||
// Test the username against the pattern.
|
||||
if (!usernamePattern.test(username)) return false
|
||||
|
||||
// check if the username is between 1 and 32 characters
|
||||
if (username.length < 4 || username.length > 32) {
|
||||
return false
|
||||
}
|
||||
|
||||
const reservedWords = [
|
||||
'root',
|
||||
'admin',
|
||||
'administrator',
|
||||
'sysadmin',
|
||||
'system',
|
||||
'daemon',
|
||||
'bin',
|
||||
'nobody',
|
||||
'nogroup',
|
||||
'guest',
|
||||
'user',
|
||||
]
|
||||
if (reservedWords.includes(username)) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
export function isValidEmail(email) {
|
||||
// Define a regular expression pattern for a valid email address.
|
||||
const emailPattern = /^[\w-.+]+@([\w][\w-]*\.)+[\w-]{2,}$/
|
||||
|
||||
// Test the email against the pattern.
|
||||
return emailPattern.test(email)
|
||||
}
|
||||
Reference in new issue
Block a user