Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check format of input string in text box

Status
Not open for further replies.

joesph

IS-IT--Management
Apr 5, 2005
1
CA
I have a text box on a form in my application which I want to check the format of. ie. the text box allows users to input a numeric value which can be either + or - depending on whether or not it is preceeded by a +/- symbol does anyone know how to check that the inputted value is only a numeric value preceeded by +/-
Thanks
 
Code:
procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
  if (not (Key in ['+', '-', '0'..'9']))then
   Key := #0;
end;
Cheers

--- markus
 
Good answer.

Also take a look at TMaskEdit. For integer numeric, you'd want a mask something like '
Code:
#999999999;0;
' or '
Code:
#000000000;0;
'.

Also also for integer numeric, take a look at TSpinEdit, on the Samples tab. -- Doug Burbidge mailto:dougburbidge@yahoo.com
 
If you want to test whatever was entered afterwards.
you can use this sort of construct
try
n := strtoint(edit1.text)
except
showmessage('Not a Number');
end;

Niether this or Markus answer will allow floating point numbers to be entered. But you could add '.' to the test[set].

Use the val() procedure to validate floating point input

Delphi also provides a formated edit box 'MaskEdit'
I think you can set this up to accept float formats.

Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top