How to validate if a login is valid inside . bat

Asked

Viewed 258 times

0

Dear I have the following script that allows only digits up to 07 characters, the same being letters only.

Is it possible for some validation to accept certain logins ? For example I just want to allow 02 logins up to 07 characters for access to the main menu.

 :enterlogin
 set /P "login= 1) DIGITE O SEU LOGIN: %=%"
 echo.!login!| findstr /R "[^a-zA-Z]" >nul 2>&1
 if ErrorLevel 1 (
 if not "!login:~7!"=="" (
  echo INFORME A RACF COM 07 DIGITOS
  echo.
 goto enterlogin
 )  
 echo !login! - OK
 ) ELSE (
 echo INFORME APENAS LETRAS
 echo.
 goto enterlogin
 )
  • With 2 logins you mean type name and surname or first name plus second name and each can have up to 7 digits only letters ex: Fulano Silva

2 answers

1

Well for now it is so because I did not understand this part of 2 logins:

inserir a descrição da imagem aqui

@echo off
:enterlogin
cls
echo.
set teste=
set digitos=
set "letras=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
set /P "login= 1) DIGITE O SEU LOGIN: %=%"
set "digitos=%login:~7%

for /f "Delims=%letras%" %%a in ("%login%") do set "teste=%%a"

if defined teste goto Erro01
if defined digitos goto Erro02
echo.
echo %login% - OK
echo.
pause
goto enterlogin

:Erro01
 cls
 echo.
 echo INFORME APENAS LETRAS
 echo.
 pause
 goto enterlogin


:Erro02
 cls
 echo.
 echo INFORME A RACF COM 07 DIGITOS
 echo.
 pause
 goto enterlogin 
  • Okay, let’s wait for the topic creator to manifest

1


1) Limit login using a loop for %%@ in (1,2,3), that for when %%@ == 3.

2) Get the input length and the total of letters present in the variable,

3) Concatene o comprimento da entrada + as letras presentes

4) Work with a predictive sequence that validates/checks the input: example:

rem :: for /f pega o comprimento da variável + total de letras presentes:

se input == 1, 1 caracteres e comprimento == 1 letras == 0
se input == a2, 2 caracteres e comprimento == 2 letras == 1
se input == ab5, 3 caracteres e comprimento == 3 letras == 2
se input == abc4, 4 caracteres e comprimento == 4 letras == 3
se input == abcd5, 5 caracteres e comprimento == 5 letras == 4
se input == abcde6, 6 caracteres e comprimento == 6 letras == 5
se input == abcdef7, 6 caracteres e comprimento == 6 letras == 6
  • Validating only when the input has only letters, we have the length equal to the number of occurrences of letters in the variable:
 a | ab | abc | abcd | abcde | abcdef | abcdefg
11   22    33     44      55       66        77
^^
||
|:==> número de ocorrências de letras na variável: 1 ocorrência letra 
|
:===> comprimento total da variável:  1 de comprimento

  • What will result in that logic:
se input == a, 1 caráteres e comprimento da string == 1 letras == 1 concanatenada == 11 valida!
se input == ab, 2 caráteres e comprimento da string == 2 letras == 2 concanatenada == 22 valida!
se input == abc, 3 caráteres e comprimento da string == 3 letras == 3 concanatenada == 33 valida!
se input == abcd, 4 caráteres e comprimento da string == 4 letras == 4 concanatenada == 44 valida!
se input == abcde, 5 caráteres e comprimento da string == 5 letras == 5 concanatenada == 55 valida!
se input == abcdef, 6 caráteres e comprimento da string == 6 letras == 6 concanatenada == 66 valida!
se input == abcdefg, 7 caráteres e comprimento da string == 7 letras == 7 concanatenada == 77 valida!

  • Using a predictive string in the loop to validate input by maximum length >= 7 and only letters present in the variable, already assuming actions when positive.

for %%# in (11 22 33 44 55 66 77)do echo/%%i%%h|findstr /lb "%%#" >nul && goto :next


Q430220.cmd


@echo off && setlocal enabledelayedexpansion && break off

cls & title <nul && title [%computername%] ...\%~nx0
for /f %%a in ('echo/prompt $h^|cmd')do set "_b=%%a" 

for %%@ in (1,2,3)do ( 
 echo/ & if %%@ gtr 1 (
      color 4F && %__APPDIR__%rundll32.exe %__APPDIR__%cmdext.dll,MessageBeepStub
      echo= -^> INFORME A RACF COM ATE 07 DIGITOS ^| INFORME APENAS LETRAS
      echo= -^> Pressione qualquer tecla...^!! && %__APPDIR__%timeout -1 >nul 
      if %%@ equ 3 echo/ -^> [ !input! - not valid input ^] & endlocal & goto :EOF
     ) 
 color 80 && set "_t=!time:~0,5!" && for /f ^tokens^=^1^delims^=^. %%i in ('
 %__APPDIR__%wbem\wmic.exe OS Get localdatetime^|findstr [0-9]')do set "_dt=%%~i"
 set "_data=!_dt:~6,2!/!_dt:~4,2!/!_dt:~0,4! !_t: =0!" && cls & echo/ & echo/
 echo= ^| Computador: [%computername%] Usuario logado: [%username%]
 set /p "input=^|!_b! ^| [ 0%%@/02 ] !_data! DIGITE O SEU LOGIN: "
 echo/ ---------------------------------------------------------
 for /f %%h in ('cmd /u/s/v/c set /p "=!input:  = !"^<nul^|find /v /c ""')do for /f %%i in ('
 cmd/u/s/v/c set/p "=!input:  = !"^<nul^|find /v " "^|%__APPDIR__%findstr [a-Z]^|find /v /c ""
 ')do for %%# in (11 22 33 44 55 66 77)do echo/%%i%%h|findstr /lb "%%#" >nul && goto :next
)

:next 
echo= [ !input! - OK ] && endlocal && goto :EOF
  • 1

    Support: Xtreme Go Horse

  • @Itwasn'tme What you use to make the screenshots?

  • @Ricardobohner Uso S2G and in the background it uses ffmpeg

Browser other questions tagged

You are not signed in. Login or sign up in order to post.