Рекурсивный вызов Name-Label
совершенно не нужен, вы можете сделать это с помощью простого цикла do{}until()
:
Function Name-Label
{
# Import Visual Basic into script
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$firstRun = $true
# show the Pop Up with the following text.
do{
if(-not $firstRun){
# loop running again, must have failed input validation
$null = (New-Object -ComObject WScript.Shell).Popup("Vous avez tapé ce nom $label qui est trop long pour la clé USB`r `n Pas plus de 11 caractères`r `n Nouvel essai !",0,"ERREUR !",0)
}
$firstRun = $false
# prompt user for label
$label = [Microsoft.VisualBasic.Interaction]::InputBox("Pas plus de 11 caractères`r`n`
1) Que des lettres ou des chifres`
2) Pas de caractères bizarres comme $ * µ %",
"Nom de la clef USB", "")
} until ($label -match '^[\d\p{L}]{1,11}$')
return $label
}
Шаблон регулярного выражения, используемый для проверки входных данных, выглядит следующим образом:
^[\d\p{L}]{1,11}$
^ # start of string
[
\d # digits
\p{L} # Letters
]
{1,11} # between 1 and 11 of the previous character class
$ # end of string