I am attempting to write a program that expects the value of a specific field to be a five-digit zip code. Logically, this should be a completely numeric value, but as I'm using a text field, it is possible for the end user to put anything in there. I'm trying to figure out how to stop this.

Is there any built-in command in Delphi that can be used to check whether or not the contents of a string are completely numeric, without throwing a major exception? Or do I need to start breaking out the try/except blocks to cover against this possibility?

I've checked the Delphi help file included in my installation, but there doesn't seem to be anything that can do what I'm after...or if there is, I have no clue what to look under.

Can anyone (and would someone) please tell me either a command that can do what I'm trying to do, or someplace else to try looking for such a command? Or, failing that, please let me know it is impossible without throwing try/except blocks around?

Thank you for your consideration,
-EnderX

i hope that what i'm doing now it will not be against the forum rules.
anyway, we are here te help and get helped.
you will find a free component at this address: http://delphi.about.com/library/weekly/code/src070603.zip
you can browse through source and find out how the tedit component is overloaded, and how to input only digits.

if there is against to post other links(here i will ask the moderators to delete the link), then i suggest you to look in delphi's help section at tedit component, onkeydown event.
type
TKeyEvent = procedure (Sender: TObject; var Key: Word; Shift: TShiftState
) of object;
property OnKeyDown: TKeyEvent;

here you can manage the input caracters. also be aware at special inputs(enter, esc, etc).


best regards,

i think you could use delphi's fascility to change string to number {strtoint()} and trap the procedure with Try except

Example:
Function ChekNumber(str:string):boolean
var dummy:integer;
begin
try
begin
dummy:=strtoint(str);
result:=true;
end;
except
result:=false;
end;

and for the 5 digit, you can use length(string) to check the length of string

i hope it works.....

This article has been dead for over six months. Start a new discussion instead.