end of day 4 week 1
This commit is contained in:
28
week 1/day 4/exo3.ps1
Normal file
28
week 1/day 4/exo3.ps1
Normal file
@@ -0,0 +1,28 @@
|
||||
# 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");
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user