Number Checking string input in Delphi?

Reply

Join Date: Aug 2006
Posts: 999
Reputation: EnderX is an unknown quantity at this point 
Solved Threads: 1
EnderX EnderX is offline Offline
Posting Shark

Number Checking string input in Delphi?

 
0
  #1
Dec 12th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 171
Reputation: radu84 is an unknown quantity at this point 
Solved Threads: 16
radu84 radu84 is offline Offline
Junior Poster

Re: Number Checking string input in Delphi?

 
0
  #2
Dec 13th, 2006
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/week.../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,
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 1
Reputation: Ferpudy is an unknown quantity at this point 
Solved Threads: 0
Ferpudy Ferpudy is offline Offline
Newbie Poster

Re: Number Checking string input in Delphi?

 
0
  #3
Apr 29th, 2007
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.....
Last edited by Ferpudy; Apr 29th, 2007 at 3:54 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC