Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Input Validation

Posted on 1998-11-05
1
Medium Priority
?
351 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 8

Accepted Solution

by:
ZifNab earned 20 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

722 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