funkcja sprawdzająca login.

0

Zrobilem taka funkcje.... Troche tepa ale coz... Dziala prawie dobrze...

// funkcja sprawdza poprawnosc wpisanego loginu //
function SprawdzLogin(l:string):boolean;
var i:integer;
begin
 if l='' then SprawdzLogin:=false;
 for i:=1 to length(l) do
 begin
  if ((l[i]<>'a') and (l[i]<>'b') and (l[i]<>'c') and (l[i]<>'d') and (l[i]<>'e') and (l[i]<>'f') and (l[i]<>'g') and (l[i]<>'h') and (l[i]<>'i') and (l[i]<>'j') and (l[i]<>'k') and (l[i]<>'l') and (l[i]<>'m') and (l[i]<>'n') and (l[i]<>'o') and (l[i]<>'p') and (l[i]<>'q') and (l[i]<>'r') and (l[i]<>'s') and (l[i]<>'t') and (l[i]<>'u') and (l[i]<>'w') and (l[i]<>'x') and (l[i]<>'y') and (l[i]<>'z'))
   then SprawdzLogin:=false
   else SprawdzLogin:=true
 end;
end;

Po wpisaniu np. "asd12asdgq" zwraca wartosc false, po wpisaniu np. "asdb" zwraca wartosc true.. i o to mi chodzilo,
jednak czemu po wpisaniu np. "asd asd" (ze spacja) rowniez zwraca wartosc true?

0

Zrób sobie stałą Chars:String='qwertyuiopasdfghjklzxcvbnm'; i następnie funkcją pos sprawdzaj czy dany znak loginu znajduje sie na tej liscie.

Bo ta twoja funkcja sprawdza ostatni znak i jeżeli jest on OK to wtedy wartość funkcji jest True.

0

a nie łatwiej tak??

function SprawdzLogin(l:string):boolean;
var i:integer;
begin
 if l='' then 
 result:=false
 else
 if l='asdb' then
 result:=true
 else
 result:=false;
   
 end;
end; 
0

Ta funkcja sprawdza czy zostały podane prawidłowe znaki, a ta Twoja sprawdza czy login jest równy asdb.

Twoją funkcje można przedstawić tak:

Function SprawdzLogin(Const Login:String):boolean;
begin
  Result:=Login='asdb';
end;
0

Szymek rzeczywiscie, nie zalapalem ze ta funkcja zle dziala i sprawdza tylko ostatni znak... Z tym pos sie nie bede bawil bo nigdy tego nie robilem a niechce mi sie szukac ;P

Wystarczylo zamienic na cos takiego jak ponizej i juz dziala oks... Thx za podpowiedz ^^

function SprawdzLogin(l:string):boolean;
var i:integer;
begin
 SprawdzLogin:=true;
 if l='' then SprawdzLogin:=false;
 for i:=1 to length(l) do
 begin
  if ((l[i]<>'a') and (l[i]<>'b') and (l[i]<>'c') and (l[i]<>'d') and (l[i]<>'e') and (l[i]<>'f') and (l[i]<>'g') and (l[i]<>'h') and (l[i]<>'i') and (l[i]<>'j') and (l[i]<>'k') and (l[i]<>'l') and (l[i]<>'m') and (l[i]<>'n') and (l[i]<>'o') and (l[i]<>'p') and (l[i]<>'q') and (l[i]<>'r') and (l[i]<>'s') and (l[i]<>'t') and (l[i]<>'u') and (l[i]<>'w') and (l[i]<>'x') and (l[i]<>'y') and (l[i]<>'z'))
   then SprawdzLogin:=false;
 end;
end;
0
function SprawdzLogin(l:string):boolean;
var i:integer;
begin
 result:=true;
 for i:=1 to length(l) do if not(L[i] in ['a'..'z']) then result:=false;
end;

To tylko dla małych liter wiec jak chcesz dla dużych też to daj: in['a'..'z','A'..'Z']..
:]

1 użytkowników online, w tym zalogowanych: 0, gości: 1