| View previous topic :: View next topic |
| Author |
Message |
YellowEye How do I cheat?
Reputation: 0
Joined: 18 Dec 2008 Posts: 5
|
Posted: Thu Feb 05, 2009 7:20 am Post subject: [Help] [Delphi] Check if letters or digits entered? |
|
|
Hello, I want to ask all of you, if someone knows how to check if letters (characters) - for example A,B,C... or digits(numbers) - for example 1,2,3 ... or both of them (characters and numbers) - for example A,1,B,2 are typed in edit1.
If you don't understand: I have edit1 and a button1. So here is my question: If I press the button1, I want to see a messagebox which says "In your edit1 you have typed only characters " or "In your edit1 you have typed only letters "
Can someone help me with source code? Thank you.
|
|
| Back to top |
|
 |
NothingToShow Grandmaster Cheater Supreme
Reputation: 0
Joined: 11 Jul 2007 Posts: 1579
|
Posted: Thu Feb 05, 2009 8:26 am Post subject: |
|
|
Found a function on the internet, dunno if it works.
isDigit
| Code: |
function isDigit(ch: char): boolean;
begin
if ch in ['0'..'9'] then
isDigit := true
else
isDigit := false;
end; |
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Thu Feb 05, 2009 8:41 am Post subject: |
|
|
| Clopin wrote: | Found a function on the internet, dunno if it works.
isDigit
| Code: |
function isDigit(ch: char): boolean;
begin
if ch in ['0'..'9'] then
isDigit := true
else
isDigit := false;
end; |
|
Why post something you don't know what it is and idioticly not answering his question ?
what you posted checks a specific char within the range 0 to 9.
Edit: to answer your question, manipulate the string entered in the Text Box by seperating each char and comparing.
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Thu Feb 05, 2009 10:25 am Post subject: |
|
|
| what are you using the fetch the string ? GetDlgItemText ? if so, the return value is number of characters copied to the buffer.
|
|
| Back to top |
|
 |
Tsabo Cheater
Reputation: 0
Joined: 03 Feb 2009 Posts: 44 Location: Texas
|
Posted: Sun Feb 08, 2009 8:21 pm Post subject: |
|
|
Use the TryStrToInt routine found in the SysUtils unit provided by CodeGear. Here is an example that utilizes that routine.
| Code: | function IsNumeric(const AValue: string): Boolean;
var
Value: Integer;
begin
Result := TryStrToInt(AValue, Value);
end;
|
Regards
|
|
| Back to top |
|
 |
|