24 lines
555 B
PowerShell
24 lines
555 B
PowerShell
$users = @("admin", "root1", "John_Doe", "Alice", "Bob42")
|
|
|
|
foreach($username in $users){
|
|
|
|
$badChar = $false
|
|
|
|
foreach($char in $username.ToCharArray()){
|
|
if($char -notmatch '[A-Za-z]' -or $char -eq ' '){
|
|
$badChar = $true
|
|
break
|
|
}
|
|
|
|
}
|
|
|
|
$firstLetter = $username[0]
|
|
$validFirstLetter = $firstLetter -match '[A-Za-z]'
|
|
|
|
if(-not $badChar -and $username.Length -le 20 -and $validFirstLetter ){
|
|
Write-Host("$username is valid");
|
|
}else{
|
|
Write-Host("$username is Invalid");
|
|
|
|
}
|
|
} |