28 lines
645 B
PowerShell
28 lines
645 B
PowerShell
# accept the username only if
|
|
# it contain letters, the username is inferior at 20
|
|
# start with a letter, no digit, no space
|
|
|
|
$username = Read-Host("Please enter your username");
|
|
$badChar = $false;
|
|
|
|
if($username -eq ''){
|
|
Write-Host("The username can't be empty");
|
|
exit;
|
|
}
|
|
|
|
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("Accepted");
|
|
}else{
|
|
Write-Host("Invalid");
|
|
|
|
} |