| | |
Number Checking string input in Delphi?
![]() |
•
•
Join Date: Aug 2006
Posts: 999
Reputation:
Solved Threads: 1
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
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
•
•
Join Date: Dec 2006
Posts: 171
Reputation:
Solved Threads: 16
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,
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,
•
•
Join Date: Apr 2007
Posts: 1
Reputation:
Solved Threads: 0
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.....
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.
![]() |
Similar Threads
- Use string input for enum (C++)
- Finding the first number char in a string (Java)
- Error Checking for user input (Java)
- error checking of user input (C++)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: programming asistance needed in delphi
- Next Thread: OMEGA components
| Thread Tools | Search this Thread |





