Solved

Input Validation

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 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