FMX.Edit.TCustomEdit.OnValidate

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

property OnValidate: TValidateTextEvent read GetOnValidate write SetOnValidate;

C++

__property Fmx::Text::TValidateTextEvent OnValidate = {read=GetOnValidate, write=SetOnValidate};

Properties

Type Visibility Source Unit Parent
event public
FMX.Edit.pas
FMX.Edit.hpp
FMX.Edit TCustomEdit

Description

Occurs after the user presses the ENTER key or the focus leaves the control.


Write an OnValidate event handler to validate any edits the user enters in the edit control before the text has changed. The OnValidate event handler can verify the supplied text and, if it is not acceptable, return an error or warning message.

Code Snippets

To clarify, consider the following scenario: an application provides a text edit box designed to enter a user email address from the mycompany.com domain, such as John.Doe@mycompany.com. If the user enters a text that does not end with the "mydomain.com" substring, the application displays an error message in the edit control.

In this scenario, you can implement the following OnValidate event handlers:

Delphi:

procedure TForm1.Edit1Validate(Sender: TObject; var Text: string);
begin
  if not EndsText('mycompany.com', Text) then
      Text := 'Invalid email!'
end;

C++Builder:

void __fastcall TForm1::Edit1Validate(TObject *Sender, UnicodeString &Text)
{
	if (!EndsText("mycompany.com", Text))  {     Text = "Invalid email!";

	}
}

Note: These code snippets use the System.StrUtils.EndsText routine.

See Also