Solved

Input Validation

Posted on 1998-11-05
1
349 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

726 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