how to validate Edit to only numbers & only text i

2019-06-13 06:29发布

问题:

This question already has an answer here:

  • Required a number in text box in Inno Setup 3 answers

Is there a way to limit the characters to numbers and lenght to 10 with no space and another edit for just ? its for a phone number, and name that needs to have no spaces, dont have an idea how to do it. Found a code that try some ways to implement but dont work here is what I found for dont allow letters.

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if (Key in ['a'..'z']) or (Key in ['A'..'Z'])  then
    Key := #0;
end;

Here for dont allow numbers:

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key in ['0'..'9'] then
    Key := #0;
end;

and this for no space:

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if key = Char(VK_SPACE) then
    Key := #0;
end;

can implement something similar in inno?

回答1:

You can edit MaxLength property of Edit1 to limit character

Edit1.MaxLength:=10;