Solved

Input Validation

Posted on 1998-11-05
1
343 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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

763 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

7 Experts available now in Live!

Get 1:1 Help Now