RTL.RegExpressionVCL Sample

From RAD Studio Code Examples
Jump to: navigation, search

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

Location

You can find the RegExpDemo sample project at:

Description

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

The form contains a list box, a memo, an edit box, and a button. 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 and click Evaluate to see whether the input is valid according to the regular expression.

How to Use the Sample

  1. Navigate to the location given above and open RegExpDemo.dproj.
  2. Press F9 or choose Run > Run.

Files

This project has one source file, Main, which contains the class for the main form.

Classes

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

Implementation

  • When an item is selected from the list box, the corresponding regular expression is added to the TMemo.
  • The input string is evaluated with the TRegEx.IsMatch method.
  • A message shows whether the input corresponds with a regular expression or not.

Uses

See Also