RTL.RegExpressionFMX Sample

From RAD Studio Code Examples
Jump to: navigation, search

RegExpressionDemo is a sample that demonstrates how to use regular expressions in an application.

Location

You can find the RegExpressionDemo sample project at:

Description

This application allows the user to test the validity of a string with regards to a regular expression.

The form contains a list box, a memo, and an edit box. From the list box the user can choose to validate an e-mail address, an IP address, or a date in either of two formats. When one of the options is selected from the TListBox, the regular expression that is used for validation is displayed in the TMemo component. Next, the user can enter a string in the TEdit to see whether the input is valid according to the regular expression.

How to Use the Sample

  1. Navigate to one of the locations given above and open:
    • Delphi: RegExpressionDemo.dproj.
    • C++: CppRegExFMX.cbproj.
  2. Press F9 or choose Run > Run.

To interact with the sample:

  • Select the type of expression from the lbRegExp list box.
  • Type the input string you want to evaluate in the EditText edit.
  • The shadow effect of the EditText edit turns green when the input matches the regular expression.
  • You can edit the regular expression in the MemoRegEx memo.

Files

File in Delphi File in C++ Contains

RegExpressionDemo.dproj

CppRegExFMX.cbproj

The project itself.

Main.fmx

Main.fmx

The main form where the components are located.

Main.pas

Main.h, Main.cpp

Implementation of the sample.

Classes

TForm1, the class for the main form, handles the display of visual components and the validation of strings by using regular expressions.

Implementation

  • The TListBox.OnChange event is used to know when an item is selected on the list box; then the corresponding regular expression is added to the TMemo.
  • The input string is evaluated with the TRegEx.IsMatch method.
  • A TShadowEffect activates on the EditText edit and displays in green or red depending on whether the input corresponds with the regular expression or not.

Uses

See Also