История изменений
Исправление
tz4678,
(текущая версия)
:
var s = 'sperma'
undefined
/^[a-z\d]+$/i.test(s) && /[A-Z]/.test(s) && /[a-z]/.test(s) && /\d/.test(s)
false
var s = 'ozon671games'
undefined
/^[a-z\d]+$/i.test(s) && /[A-Z]/.test(s) && /[a-z]/.test(s) && /\d/.test(s)
false
var s = 'Mamoep1488'
undefined
/^[a-z\d]+$/i.test(s) && /[A-Z]/.test(s) && /[a-z]/.test(s) && /\d/.test(s)
true
Без регулярок:
function isValidUsername(s) {
let digits = false
let upper = false
let lower = false
for (let c of s) {
if (c >= '0' && c <= '9') {
digits = true
} else if (c >= 'a' && c <= 'z') {
lower = true
} else if (c >= 'A' && c <= 'Z') {
upper = true
} else {
return false
}
}
return (digits && lower && upper)
}
Исправление
tz4678,
:
var s = 'sperma'
undefined
/^[a-z\d]+$/i.test(s) && /[A-Z]/.test(s) && /[a-z]/.test(s) && /\d/.test(s)
false
var s = 'ozon671games'
undefined
/^[a-z\d]+$/i.test(s) && /[A-Z]/.test(s) && /[a-z]/.test(s) && /\d/.test(s)
false
var s = 'Mamoep1488'
undefined
/^[a-z\d]+$/i.test(s) && /[A-Z]/.test(s) && /[a-z]/.test(s) && /\d/.test(s)
true
Без регулярорк:
function isValidUsername(s) {
let digits = false
let upper = false
let lower = false
for (let c of s) {
if (c >= '0' && c <= '9') {
digits = true
} else if (c >= 'a' && c <= 'z') {
lower = true
} else if (c >= 'A' && c <= 'Z') {
upper = true
} else {
return false
}
}
return (digits && lower && upper)
}
Исходная версия
tz4678,
:
var s = 'sperma'
undefined
/^[a-z\d]+$/i.test(s) && /[A-Z]/.test(s) && /[a-z]/.test(s) && /\d/.test(s)
false
var s = 'ozon671games'
undefined
/^[a-z\d]+$/i.test(s) && /[A-Z]/.test(s) && /[a-z]/.test(s) && /\d/.test(s)
false
var s = 'Mamoep1488'
undefined
/^[a-z\d]+$/i.test(s) && /[A-Z]/.test(s) && /[a-z]/.test(s) && /\d/.test(s)
true