/
githubmirror
/
client
Обзор
Документация
Войти
/
githubmirror
/
client
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
shared/util/simple-validators.tsx
70 строк
2 KB
chrisnojima-zoom
Version 670 - clean2 (#29122)
08 июн 2026, 19:31
Не верифицирован
08 июн 2026, 19:31
1943197
Код
Авторство
О чём код?
function isBlank(s: string): boolean { return s.trim().length === 0 } function hasSpaces(s: string): boolean { return s.includes(' ') } function hasPeriod(s: string): boolean { return s.includes('.') } function hasAtSign(s: string): boolean { return s.includes('@') } function isEmptyOrBlank(thing?: string): boolean { if (!thing || isBlank(thing)) { return true } return false } // Returns an error string if not valid function isValidCommon(thing?: string): string { if (isEmptyOrBlank(thing)) return 'Cannot be blank' if (thing && hasSpaces(thing)) return 'No spaces allowed' return '' } // Returns an error string if not valid function isValidUsername(username?: string): string { if (!username) { return '' } const commonError = isValidCommon(username) if (commonError) { return commonError } if (hasPeriod(username)) { return "Usernames can't contain periods." } if (username.startsWith('_')) { return "Usernames can't start with an underscore." } if (username.includes('__')) { return "Usernames can't contain double underscores to avoid confusion." } return '' } // Returns an error if not valid function isValidEmail(email?: string): string { const commonError = isValidCommon(email) if (!commonError) { if (email && hasAtSign(email)) { return '' } } return email ? 'Invalid email address.' : 'Empty email address.' } // Returns an error string if not valid function isValidName(name?: string): string { if (isEmptyOrBlank(name)) return 'Please provide your name.' return '' } export {isValidUsername, isValidEmail, isValidName}