Subscribe to AppGini tips and tutorials using your favorite RSS news reader by clicking the link to the right.
Read more AppGini tips and tutorials

Formatting a field as a phone number


Q: I need to automatically format data in a field as a phone number like XXX-XX-XXXX. How can I do so?

A: AppGini supports automatic formatting of data by using the Data Format tab. Select any field in AppGini, and go to that tab. You can then select a data format from the list, as shown in this screen shot below.

Field data formats in AppGini

We can add more formats to this list easily. For example, we can add phone number formatting like the above question. To do so, we should edit the dataFormats.cfg file using a text editor. You can find this file in the add-ons folder inside the folder where AppGini is installed (usually C:\Program Files\AppGini). The line that we need to add for formatting phone numbers is:

Phone number (example: 123-45-6789); CONCAT_WS('-', LEFT(%%FIELD%%,3), MID(%%FIELD%%,4,2), RIGHT(%%FIELD%%,4))

The syntax of this line is easy: A human-readable description of the format, followed by a semi-colon, followed by the MySQL syntax to be used in formatting the field. The %%FIELD%% placeholder in this syntax tells AppGini where to put the field name in the generated code. After adding the above line to the dataFormats.cfg file, we can see the new format in the data formats list in AppGini, as shown in the screen shot below.

Adding a custom data format for phone numbers.

After applying this format to our field and generating the application, data in that field will be automatically formatted as phone numbers, as seen in the screen shot below.

The phone number format automatically applied to data in a field