Solved

Input Validation

Posted on 1998-11-05
1
345 Views
Last Modified: 2010-04-04
Hi

How do I validate that the contents of an edit box (input by the user) is a positive integer?

Thanks
0
Comment
Question by:cavalry
1 Comment
 
LVL 8

Accepted Solution

by:
ZifNab earned 10 total points
ID: 1345806
Hi cavalry,

3 options :

1. Use Tedit and check the entered value when exiting the editbox
2. Use MaskEdit with an editmask which only allows figures.
3. Use a special designed numeric edit (a lot freewares!)
   --> e.g. One in the freeware RxLib (http://rx.demo.ru)
     

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Mask;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    MaskEdit1: TMaskEdit;
    procedure Edit1Exit(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Edit1Exit(Sender: TObject);
begin
 try
  If StrToInt(Edit1.text) < 0 then begin
   ShowMessage('not correct value');
   Edit1.Text := '0';
  end;
 except
  // Edit1.Text contains chars
   ShowMessage('fill in only an integer value');
   Edit1.Text := '0';
 end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 Edit1.text := '0';
 MaskEdit1.EditMask:= '00000;1;';   {or 999999;1; }
end;

end.

Regards, Zif.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now