ClickCease Validate Form Fields with Regex - Help Center - WhatConverts

Validate Form Fields with Regex

If leads in WhatConverts contain inaccurate or improperly formatted data, such as invalid email addresses or placeholder text in phone number fields, the issue is typically that your form fields are not validating input before submission. WhatConverts honors the HTML5 pattern attribute, which means you can use Regular Expressions (Regex) to prevent the form from submitting until a field matches a defined format. This article explains how to implement Regex validation to improve lead data quality.

Form fields are accepting inaccurate or incorrectly formatted input

Marking a field as required ensures it is not left blank, but it does not guarantee the data entered is valid. Without Regex validation, users can submit fields with placeholder text, incorrect formats, or spam content, all of which WhatConverts will capture as lead data.

How to add Regex validation to a form field

To troubleshoot this issue:

  1. Open your website's HTML and locate the <input> tag for the field you want to validate.
  2. Add the pattern attribute to the field along with the required attribute to ensure the field cannot be skipped.
  3. Use the appropriate Regex pattern for your validation goal. See the common patterns below.
  4. Test the form by entering incorrectly formatted data and confirming the browser prevents submission until the input matches the required pattern.
  5. Submit a correctly formatted test lead and verify the data appears accurately in your WhatConverts Lead Manager.

Example: Validating an email address field

<input type="email" name="email" pattern="^[a-zA-Z0-9.!#$%&'*+/=?^__{|}~-]+@[a-zA-Z0-9-]+(?:.[a-zA-Z0-9-]+)" required>

Common Regex patterns for lead field validation

Use the following patterns to address the most frequent lead data quality issues:

Validation GoalRegex Pattern Snippet
US Phone Numberpattern="^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$"
5-Digit Zip Codepattern="(\d{5}([\-]\d{4})?)"
Numbers Onlypattern="^[0-9]*$"
No URL/Linkspattern="^((?!http).)*$" (Useful for preventing spam)

 

Note: Regex validation also helps prevent duplicate leads. When a field fails validation and the user corrects and resubmits, WhatConverts only captures the final successful submission. See the Fix Incomplete Form Lead Data article for more detail on how this works.

Related Topics

Get a FREE presentation of WhatConverts

One of our marketing experts will give you a full presentation of how WhatConverts can help you grow your business.

Schedule a Demo
ready to get marketing clarity?

Grow your business with WhatConverts

14 days free trial Easy setup Dedicated support
G2 Best Results Summer 2025 Badge
G2 Best Relationship Summer 2025 Badge
G2 Best Usability Summer 2025 Badge
G2 Most Implementable Summer 2025 Badge
G2 Momentum Leader Summer 2025 Badge