# Building a Credit Card Payment Form with Conditional Instructions

> You can use the Document Viewer to deploy document forms with form field elements that contain conditional instructions for users to complete. This article shows how to use the Document Editor to set up and deploy a credit card payment form with credit card validation logic.

- **Author:** Bjoern Meyer
- **Published:** 2023-03-24
- **Modified:** 2026-07-17
- **Description:** You can use the Document Viewer to deploy document forms with form field elements that contain conditional instructions for users to complete. This article shows how to use the Document Editor to set up and deploy a credit card payment form with credit card validation logic.
- **4 min read** (705 words)
- **Tags:**
  - ASP.NET
  - Forms
  - Document Viewer
- **Web URL:** https://www.textcontrol.com/blog/2023/03/24/building-a-credit-card-payment-form-with-conditional-instructions/
- **LLMs URL:** https://www.textcontrol.com/blog/2023/03/24/building-a-credit-card-payment-form-with-conditional-instructions/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2023/03/24/building-a-credit-card-payment-form-with-conditional-instructions/llms-full.txt

---

TX Text Control provides a unique way to create documents with fillable form elements such as form text boxes, checkbox fields, and drop-down elements. These forms can be created like mail merge templates and dynamically populated with values from form data sources. Using conditional statements, it is possible to add dependencies between fields based on logical operators. This allows you to add a complete workflow to forms by adding dependencies between form fields.

You can use the Document Viewer to deploy document forms with form field elements that contain conditional instructions for users to complete.

### Smart Forms

Let's take a look at the simple payment form in the screenshot below:

![Creating documents with TX Text Control](https://s1-www.textcontrol.com/assets/dist/blog/2023/03/24/a/assets/form1.webp "Creating documents with TX Text Control")

Creating this form layout is really easy using the word processing interface of the TX Text Control Document Editor. All you need to do is to create a document with a table structure and form fields that can be added using the *Form Fields* ribbon tab. This article does not describe that part, but the smart logic behind the form fields.

Download the [sample form](https://s1-www.textcontrol.com/assets/dist/blog/2023/03/24/a/assets/payment_form.tx) and load it into the Document Editor or the shipped Windows application *TX Text Control Words*.

### Form Validation

In order to add conditional instructions to the form fields, you have to enable the validation by clicking the button *Enable Form Validation* in the *Form Validation* ribbon group.

![Creating documents with TX Text Control](https://s1-www.textcontrol.com/assets/dist/blog/2023/03/24/a/assets/form2.webp "Creating documents with TX Text Control")

This form contains 11 conditional instructions to cover the logic and validation of a credit card. Open the instruction named *Payment\_Card\_Number\_GetValue* by selecting it and clicking *Edit...*.

![Creating documents with TX Text Control](https://s1-www.textcontrol.com/assets/dist/blog/2023/03/24/a/assets/form3.webp "Creating documents with TX Text Control")

### Regular Expressions

This instruction validates the *payment\_number* form field by matching a regular expression for each payment method. For example: If the *VISA* checkbox is checked and the number matches the conditions that it starts with a 4 and is 12 digits long, the field is valid. Here are the characteristics of the credit cards used:

- **VISA**
    - All VISA card numbers start with a 4.
    - New cards have 16 digits. Old cards have 13.
- **Mastercard**
    - MasterCard numbers either start with the numbers 51 through 55 or with the numbers 2221 through 2720.
    - All cards have 16 digits.
- **AMEX**
    - All AMEX cards start with 34 or 37
    - All cards have 15 digits.

### Enable Checkboxes Automatically

To improve the user experience, the checkbox can be set automatically by matching the credit card number. This can be seen in the instruction *Payment\_Card\_Number\_VISA\_SetValue* for matching VISA credit card numbers:

![Creating documents with TX Text Control](https://s1-www.textcontrol.com/assets/dist/blog/2023/03/24/a/assets/form4.webp "Creating documents with TX Text Control")

If the credit number is recognized as a VISA card, the appropriate checkbox is checked and others are unchecked. When you load a document with form fields and conditional instructions into the Document Viewer, the form fields are automatically enabled:

![Creating documents with TX Text Control](https://s1-www.textcontrol.com/assets/dist/blog/2023/03/24/a/assets/forms.gif "Creating documents with TX Text Control")

The other conditional instructions are simpler and check for non-empty fields. The only more complex field is CCV, as the validity of this field again depends on the credit card selected. 3 digits for VISA and Mastercard and 4 digits for AMEX.

![Creating documents with TX Text Control](https://s1-www.textcontrol.com/assets/dist/blog/2023/03/24/a/assets/form5.webp "Creating documents with TX Text Control")

### Validate using JavaScript

If all fields are filled in correctly, the forms.validate JavaScript method can be used to validate the form fields.

![Creating documents with TX Text Control](https://s1-www.textcontrol.com/assets/dist/blog/2023/03/24/a/assets/form6.webp "Creating documents with TX Text Control")

You can download this [sample form](https://s1-www.textcontrol.com/assets/dist/blog/2023/03/24/a/assets/payment_form.tx) here for your own testing.

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [Programmatically Fill, Flatten, and Export DOCX Form Templates to PDF in C# .NET](https://www.textcontrol.com/blog/2026/04/10/programmatically-fill-flatten-and-export-docx-form-templates-to-pdf-in-csharp-dotnet/llms.txt)
- [Create Fillable PDFs from HTML Forms in C# ASP.NET Core Using a WYSIWYG Template](https://www.textcontrol.com/blog/2026/03/17/create-fillable-pdfs-from-html-forms-in-csharp-aspnet-core-using-a-wysiwyg-template/llms.txt)
- [Designing the Perfect PDF Form with TX Text Control in .NET C#](https://www.textcontrol.com/blog/2025/12/16/designing-the-perfect-pdf-form-with-tx-text-control-in-dotnet-csharp/llms.txt)
- [Streamline Data Collection with Embedded Forms in C# .NET](https://www.textcontrol.com/blog/2025/08/02/streamline-data-collection-with-embedded-forms-in-csharp-dotnet/llms.txt)
- [High-Performance Text Replacement in Large DOCX Files using C# .NET](https://www.textcontrol.com/blog/2025/07/30/high-performance-text-replacement-in-large-docx-files-using-csharp-dotnet/llms.txt)
- [Document Viewer 33.2.1 Released: New Event and Bug Fixes](https://www.textcontrol.com/blog/2025/07/30/document-viewer-33-2-1-released-new-event-and-bug-fixes/llms.txt)
- [Building an ASP.NET Core Backend (Linux and Windows) for the Document Editor and Viewer](https://www.textcontrol.com/blog/2025/03/26/building-an-asp-net-core-backend-for-the-document-editor-and-viewer/llms.txt)
- [TX Text Control Document Editor and Viewer for Blazor Released](https://www.textcontrol.com/blog/2025/03/25/tx-text-control-document-editor-and-viewer-for-blazor-released/llms.txt)
- [Getting Started: Document Viewer for Blazor in ASP.NET Core](https://www.textcontrol.com/blog/2025/03/25/getting-started-document-viewer-for-blazor-in-asp-net-core/llms.txt)
- [Convert MS Word DOCX to PDF with Form Fields in C# .NET: Preserve or Flatten Form Fields](https://www.textcontrol.com/blog/2025/02/26/convert-ms-word-docx-to-pdf-with-form-fields-in-csharp-dotnet/llms.txt)
- [Announcing Our Work on a Blazor Component for Document Editing and Viewing](https://www.textcontrol.com/blog/2025/01/24/announcing-our-work-on-a-blazor-component-for-document-editing-and-viewing/llms.txt)
- [Export and Import Adobe PDF XFDF XML Files in .NET C#](https://www.textcontrol.com/blog/2025/01/22/export-and-import-adobe-pdf-xfdf-xml-files-in-net-c-sharp/llms.txt)
- [Preparing Documents for E-Signing for Multiple Signers in .NET C#](https://www.textcontrol.com/blog/2024/11/13/preparing-documents-for-e-signing-for-multiple-signers-in-net-c-sharp/llms.txt)
- [ASP.NET Core: Use the Document Editor and Viewer in the Same Razor View](https://www.textcontrol.com/blog/2024/11/08/asp-net-core-use-the-document-editor-and-viewer-in-the-same-razor-view/llms.txt)
- [Optimizing Digital Signature Workflows: Starting with MS Word DOCX Files Instead of PDFs in C#](https://www.textcontrol.com/blog/2024/09/27/optimizing-digital-signature-workflows-starting-with-ms-word-docx-files-instead-of-pdfs-in-csharp/llms.txt)
- [Document Viewer: Setting the Rendering Mode](https://www.textcontrol.com/blog/2024/08/22/document-viewer-setting-the-rendering-mode/llms.txt)
- [View MS Word DOCX and PDF Documents using a .NET C# Document Viewer for ASP.NET Core and ASP.NET](https://www.textcontrol.com/blog/2024/08/08/view-ms-word-docx-and-pdf-documents-using-a-net-csharp-document-viewer-for-aspnet-core-and-aspnet/llms.txt)
- [Stay Up-To-Date: Document Viewer 32.3.1 Released](https://www.textcontrol.com/blog/2024/08/08/stay-up-to-date-document-viewer-32-3-1-released/llms.txt)
- [Getting Started Video Tutorial: How to Add Electronic and Digital Signatures to PDF Documents in ASP.NET Core C#](https://www.textcontrol.com/blog/2024/08/05/getting-started-video-tutorial-how-to-add-electronic-and-digital-signatures-to-pdf-documents-in-asp-net-core-csharp/llms.txt)
- [Getting Started Video Tutorial: How to use the Document Viewer in ASP.NET Core C#](https://www.textcontrol.com/blog/2024/08/05/getting-started-video-tutorial-how-to-use-the-document-viewer-in-asp-net-core-csharp/llms.txt)
- [Transforming Financial Documents into Smart and Secure Forms in ASP.NET Core C#](https://www.textcontrol.com/blog/2024/05/01/transforming-financial-documents-into-smart-and-secure-forms-in-asp-net-core-c-sharp/llms.txt)
- [Document Viewer: Long Polling Support for Loading Documents](https://www.textcontrol.com/blog/2024/04/25/document-viewer-long-polling-support-for-loading-documents/llms.txt)
- [Adding and Sharing Annotations across Document Types using the Document Viewer in ASP.NET Core C#](https://www.textcontrol.com/blog/2024/04/19/adding-and-sharing-annotations-across-document-types-using-the-document-viewer-in-asp-net-core-c-sharp/llms.txt)
- [Handling Form Field Data in Angular Applications](https://www.textcontrol.com/blog/2024/03/27/handling-form-field-data-in-angular-applications/llms.txt)
- [Preparing Forms for the Document Viewer and Customizing the Signing Process in Angular and ASP.NET Core](https://www.textcontrol.com/blog/2024/03/25/preparing-forms-for-the-document-viewer-and-customizing-the-signing-process-in-angular-and-asp-net-core/llms.txt)
