end of day 4 week 1

This commit is contained in:
2026-01-22 07:31:44 +01:00
parent 5120f11339
commit 82b79336ea
15 changed files with 247 additions and 0 deletions

28
week 1/day 4/exo3.ps1 Normal file
View 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");
}