Number in Edit fields

Submitted by:Pitter Alderson

Date added:02 May, 2011

Category:Delphi

Procedure which checks the number of eating properly entered in edit box with a comma

Tags: editing fields

Code Snippet:

    /*
Procedure which checks the number of eating properly entered in
edit box with a comma

Declaration in public
Provjeribroj Procedure (Sender: savings);

Call procedures for example Edit1 field
provjeribroj (Edit1);
*/

procedure TForm1.provjeribroj(Sender : TEdit);
Var i,br,st: integer;
s : String;
priv : String;
begin
br := 0;
st:= Sender.SelStart;
s := Sender.Text;
if copy(s,1,1) = DecimalSeparator then
begin
Sender.Text := copy(s,2,length(s)) ;
Sender.SelStart :=st;
exit;
end;
for i := 1 to length(s) do
begin
if s[i] in ['0'..'9',DecimalSeparator] then
begin
if (s[i] = DecimalSeparator) then
begin
br:=br+1;
end;

if not(( br>1) and (s[i] = DecimalSeparator)) then
begin
priv := priv + s[i];
end
else
st:=st-1;

end
else
begin
st:=st-1;
end

end;
Sender.Text := priv;
Sender.SelStart :=st;

end;
 
 

Comments